census-loader 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,19 @@
1
+ """A readable Python interface to the U.S. Census Bureau API."""
2
+
3
+ from .load import pull_census
4
+ from .series import ALL_SERIES, CATEGORIES, PREDICATES, SUBCATEGORIES
5
+ from .utils import Config, available, geos, info, pickle_loader, search
6
+
7
+ __all__ = [
8
+ "ALL_SERIES",
9
+ "CATEGORIES",
10
+ "Config",
11
+ "PREDICATES",
12
+ "SUBCATEGORIES",
13
+ "available",
14
+ "geos",
15
+ "info",
16
+ "pickle_loader",
17
+ "pull_census",
18
+ "search",
19
+ ]
census_loader/load.py ADDED
@@ -0,0 +1,42 @@
1
+ import pickle
2
+ import pandas as pd
3
+ from .utils import Config, _load_census_bureau
4
+ from .series import ALL_SERIES, CATEGORIES, SUBCATEGORIES
5
+
6
+ # PUBLIC API
7
+
8
+
9
+ def pull_census(config: Config) -> dict[str, pd.DataFrame] | None:
10
+ """
11
+ Pull Census Bureau data and optionally apply scoring.
12
+
13
+ Returns a dict of DataFrames keyed by friendly name, or None on failure.
14
+ Each DataFrame has rows = geographies and columns = variables + geo IDs.
15
+ The result is persisted as a pickle for lossless round-tripping.
16
+ """
17
+ cfg = config if isinstance(config, Config) else None
18
+ if cfg is None:
19
+ print("Incorrect Configuration Format.")
20
+ return None
21
+
22
+ if cfg._series_input is not None:
23
+ print(f"Custom series selection: {len(cfg.SERIES)} series to pull.")
24
+
25
+ result = _load_census_bureau(config=config)
26
+ if result is None:
27
+ return None
28
+ else:
29
+ output = result
30
+ # ── Persist ──────────────────────────────────────────────────────────
31
+ config.OUTPUT_PATH.mkdir(parents=True, exist_ok=True)
32
+
33
+ fname = config.FILENAME
34
+ if not fname.endswith(".pkl"):
35
+ fname = fname.rsplit(".", 1)[0] + ".pkl" if "." in fname else fname + ".pkl"
36
+ pkl_file = config.OUTPUT_PATH / fname
37
+
38
+ with open(pkl_file, "wb") as f:
39
+ pickle.dump(output, f)
40
+ print(f"\n Saved → {pkl_file}")
41
+
42
+ return output
census_loader/py.typed ADDED
File without changes