diff --git a/MANIFEST.in b/MANIFEST.in index 992bb65..e08203e 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,4 @@ include LICENSE include README.md include cpi/cpi.db -recursive-include notebooks * \ No newline at end of file +recursive-include notebooks * diff --git a/cpi/download.py b/cpi/download.py index d27c25c..8963606 100644 --- a/cpi/download.py +++ b/cpi/download.py @@ -59,7 +59,7 @@ def update(self) -> None: # Download the TSVs logger.debug(f"Downloading {len(self.FILE_LIST)} files from the BLS") - df_list = dict((name, self.get_df(name)) for name in self.FILE_LIST) + df_list = {name: self.get_df(name) for name in self.FILE_LIST} # Insert the TSVs logger.debug("Loading data into SQLite database") @@ -93,12 +93,13 @@ def get_df(self, file: str) -> pd.DataFrame: logger.error(f"Error downloading {url}") logger.error(f"Response: {response.text}") raise AssertionError(f"Error downloading {url} - {response.text}") - + # Read in the contents as an io.StringIO object df = pd.read_csv(io.StringIO(response.text), sep="\t") # .strip() every value in the dataframe - df.replace('(^\s+|\s+$)', '', regex=True, inplace=True) + df_obj = df.select_dtypes("object") + df[df_obj.columns] = df_obj.apply(lambda x: x.str.strip()) # .strip every column name df.columns = [c.strip() for c in df.columns] diff --git a/docs/Makefile b/docs/Makefile index 4ae5af2..8352782 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -20,4 +20,4 @@ help: @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) livehtml: - sphinx-autobuild -b html $(SOURCEDIR) $(BUILDDIR)/html \ No newline at end of file + sphinx-autobuild -b html $(SOURCEDIR) $(BUILDDIR)/html diff --git a/docs/requirements.txt b/docs/requirements.txt index 63ddc06..fa8de61 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,3 +1,3 @@ sphinx myst-parser -sphinx-palewire-theme \ No newline at end of file +sphinx-palewire-theme diff --git a/notebooks/latest.json b/notebooks/latest.json index 7e3a7f6..e6bbd2a 100644 --- a/notebooks/latest.json +++ b/notebooks/latest.json @@ -1 +1 @@ -{"all": {"latest_month": "2024-07-01", "latest_change": 0.2, "previous_month": "2024-06-01", "previous_change": -0.1}, "food": {"latest_month": "2024-07-01", "latest_change": 0.2, "previous_month": "2024-06-01", "previous_change": 0.2}, "energy": {"latest_month": "2024-07-01", "latest_change": 0.0, "previous_month": "2024-06-01", "previous_change": -2.0}, "less_food_and_energy": {"latest_month": "2024-07-01", "latest_change": 0.2, "previous_month": "2024-06-01", "previous_change": 0.1}, "yoy_change": 2.9} \ No newline at end of file +{"all": {"latest_month": "2024-07-01", "latest_change": 0.2, "previous_month": "2024-06-01", "previous_change": -0.1}, "food": {"latest_month": "2024-07-01", "latest_change": 0.2, "previous_month": "2024-06-01", "previous_change": 0.2}, "energy": {"latest_month": "2024-07-01", "latest_change": 0.0, "previous_month": "2024-06-01", "previous_change": -2.0}, "less_food_and_energy": {"latest_month": "2024-07-01", "latest_change": 0.2, "previous_month": "2024-06-01", "previous_change": 0.1}, "yoy_change": 2.9}