From aa90992331ff87c5ae81fffe430faf7885e1c9c2 Mon Sep 17 00:00:00 2001 From: jdebacker Date: Wed, 18 Sep 2024 13:21:34 -0400 Subject: [PATCH 1/9] replace use of pkg_reouces, pd.set_options --- ccc/calcfunctions.py | 2 -- ccc/utils.py | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/ccc/calcfunctions.py b/ccc/calcfunctions.py index 85cb492b..03ad8b00 100644 --- a/ccc/calcfunctions.py +++ b/ccc/calcfunctions.py @@ -3,8 +3,6 @@ from ccc.constants import TAX_METHODS, RE_ASSETS, RE_INDUSTRIES from ccc.utils import str_modified -pd.set_option("future.no_silent_downcasting", True) - ENFORCE_CHECKS = True diff --git a/ccc/utils.py b/ccc/utils.py index c8a30592..0d1c56c4 100644 --- a/ccc/utils.py +++ b/ccc/utils.py @@ -1,4 +1,4 @@ -import pkg_resources +import importlib.resources as pkg_resources from collections import OrderedDict import warnings import numbers From 2f7f35d0f9b2b8b51d77a5ed50ff778911a89479 Mon Sep 17 00:00:00 2001 From: jdebacker Date: Thu, 19 Sep 2024 11:04:50 -0400 Subject: [PATCH 2/9] use import resources to read package resources --- ccc/utils.py | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/ccc/utils.py b/ccc/utils.py index 0d1c56c4..ec79bccc 100644 --- a/ccc/utils.py +++ b/ccc/utils.py @@ -119,15 +119,9 @@ def read_egg_csv(fname, index_col=None): Returns: vdf (Pandas DataFrame): data from csv file """ - # try: - path_in_egg = os.path.join(PACKAGE_NAME, fname) try: - vdf = pd.read_csv( - pkg_resources.resource_stream( - pkg_resources.Requirement.parse(PYPI_PACKAGE_NAME), path_in_egg - ), - index_col=index_col, - ) + with pkg_resources.open_text(PACKAGE_NAME, fname) as file: + vdf = pd.read_csv(file, index_col=index_col) except Exception: raise ValueError("could not read {} data from egg".format(fname)) # cannot call read_egg_ function in unit tests @@ -147,15 +141,8 @@ def read_egg_json(fname): """ try: - path_in_egg = os.path.join(PACKAGE_NAME, fname) - pdict = json.loads( - pkg_resources.resource_stream( - pkg_resources.Requirement.parse(PYPI_PACKAGE_NAME), path_in_egg - ) - .read() - .decode("utf-8"), - object_pairs_hook=OrderedDict, - ) + with pkg_resources.open_text(PACKAGE_NAME, fname) as file: + pdict = json.loads(file.read(), object_pairs_hook=OrderedDict) except Exception: raise ValueError("could not read {} data from egg".format(fname)) # cannot call read_egg_ function in unit tests From 6796be3019d8023d381ff0ba00c823cd29fe6b96 Mon Sep 17 00:00:00 2001 From: jdebacker Date: Thu, 19 Sep 2024 11:05:16 -0400 Subject: [PATCH 3/9] use float key for dict --- ccc/tests/test_start_years.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ccc/tests/test_start_years.py b/ccc/tests/test_start_years.py index 8b8743c4..d51fbc90 100644 --- a/ccc/tests/test_start_years.py +++ b/ccc/tests/test_start_years.py @@ -33,5 +33,5 @@ def test_params_start_year(year, expected_values): """ p = Specification(year=year) assert np.allclose(p.u["c"], expected_values[0]) - assert np.allclose(p.bonus_deprec["3"], expected_values[1]) + assert np.allclose(p.bonus_deprec[3], expected_values[1]) assert np.allclose(p.phi, expected_values[2]) From 1b15cfc24b6e3ba5b739cd6fab4534613d02068c Mon Sep 17 00:00:00 2001 From: jdebacker Date: Thu, 19 Sep 2024 11:05:42 -0400 Subject: [PATCH 4/9] use float key for dict --- ccc/parameters.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ccc/parameters.py b/ccc/parameters.py index a1313157..4994f0bf 100644 --- a/ccc/parameters.py +++ b/ccc/parameters.py @@ -206,13 +206,13 @@ def compute_default_params(self): (str(i) if i != 27.5 else "27_5") for i in class_list ] self.bonus_deprec = {} - for cl in class_list_str: - self.bonus_deprec[cl] = getattr( + for i, cl in enumerate(class_list_str): + self.bonus_deprec[class_list[i]] = getattr( self, "BonusDeprec_{}yr".format(cl) )[0] # to handle land and inventories # this is fixed later, but should work on this - self.bonus_deprec["100"] = 0.0 + self.bonus_deprec[100] = 0.0 def default_parameters(self): """ From 06fe681688341b31f688df8e674e275519fd599c Mon Sep 17 00:00:00 2001 From: jdebacker Date: Thu, 19 Sep 2024 11:06:07 -0400 Subject: [PATCH 5/9] comment out income forecast from dict for now --- ccc/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ccc/constants.py b/ccc/constants.py index 03275974..28b35c92 100644 --- a/ccc/constants.py +++ b/ccc/constants.py @@ -60,7 +60,7 @@ "SL": 1.0, "Economic": 1.0, "Expensing": 1.0, - "Income Forecast": 1.0, + # "Income Forecast": 1.0, } MINOR_ASSET_GROUPS = dict.fromkeys( From 301afd436fa995dff68597ef0dd438898fa7d51c Mon Sep 17 00:00:00 2001 From: jdebacker Date: Thu, 19 Sep 2024 11:06:31 -0400 Subject: [PATCH 6/9] remove comments --- ccc/calculator.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ccc/calculator.py b/ccc/calculator.py index 844cd341..ca0b10c9 100644 --- a/ccc/calculator.py +++ b/ccc/calculator.py @@ -2000,14 +2000,10 @@ def asset_bubble( } equipment_df["short_category"] = equipment_df["minor_asset_group"] - # equipment_df['short_category'].replace(make_short, - # inplace=True) equipment_df.replace( {"short_category": make_short}, regex=True, inplace=True ) structure_df["short_category"] = structure_df["minor_asset_group"] - # structure_df['short_category'].replace(make_short, - # inplace=True) structure_df.replace( {"short_category": make_short}, regex=True, inplace=True ) From 8b280c8a9653cf3dc3c6c84c66afe91604418d10 Mon Sep 17 00:00:00 2001 From: jdebacker Date: Thu, 19 Sep 2024 11:07:11 -0400 Subject: [PATCH 7/9] fix issues with replace --- ccc/calcfunctions.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/ccc/calcfunctions.py b/ccc/calcfunctions.py index 03ad8b00..5179b68d 100644 --- a/ccc/calcfunctions.py +++ b/ccc/calcfunctions.py @@ -40,14 +40,19 @@ def update_depr_methods(df, p, dp): deprec_df, how="left", left_on="bea_asset_code", right_on="BEA_code" ) # add bonus depreciation to tax deprec parameters dataframe - # ** UPDATE THIS - maybe including bonus in new asset deprec JSON** - df["bonus"] = df["GDS_life"].apply(str_modified) + df["bonus"] = df["GDS_life"] + # update tax_deprec_rates based on user defined parameters df.replace({"bonus": p.bonus_deprec}, inplace=True) - # make bonus float format - df["bonus"] = df["bonus"].astype(float) # Compute b df["b"] = df["method"] df.replace({"b": TAX_METHODS}, regex=True, inplace=True) + # use b value of 1 if method is not in TAX_METHODS + # NOTE: not sure why the replae method doesn't work for this method + # Related: had to comment this out in TAX_METHODS + df.loc[df["b"] == "Income Forecast", "b"] = 1.0 + # cast b as float + df["b"] = df["b"].astype(float) + df.loc[df["system"] == "ADS", "Y"] = df.loc[ df["system"] == "ADS", "ADS_life" ] @@ -140,9 +145,9 @@ def econ(delta, bonus, r, pi): def income_forecast(Y, delta, bonus, r): r""" - Makes the calculation for the income forecast method. + Makes the calculation for the Income Forecast method. - The income forecast method involved deducting expenses in relation + The Income Forecast method involved deducting expenses in relation to forecasted income over the next 10 years. CCC follows the CBO methodology (CBO, 2018: https://www.cbo.gov/system/files/2018-11/54648-Intangible_Assets.pdf) From 92b2a02d7e0c3e5c0c4810048b3affeb109d718e Mon Sep 17 00:00:00 2001 From: jdebacker Date: Fri, 20 Sep 2024 22:24:16 -0400 Subject: [PATCH 8/9] bump version number --- README.md | 2 +- ccc/__init__.py | 2 +- docs/book/content/intro.md | 2 +- setup.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index abb490f9..7ccb9680 100644 --- a/README.md +++ b/README.md @@ -55,4 +55,4 @@ Results will change as the underlying models improve. A fundamental reason for a ## Citing the Cost-of-Capital-Calculator Model -Cost-of-Capital-Calculator (Version 1.5.1)[Source code], https://github.com/PSLmodels/Cost-of-Capital-Calculator +Cost-of-Capital-Calculator (Version 1.5.2)[Source code], https://github.com/PSLmodels/Cost-of-Capital-Calculator diff --git a/ccc/__init__.py b/ccc/__init__.py index 3626db7f..97d84c79 100644 --- a/ccc/__init__.py +++ b/ccc/__init__.py @@ -6,4 +6,4 @@ from ccc.data import * from ccc.calculator import * -__version__ = "1.5.1" +__version__ = "1.5.2" diff --git a/docs/book/content/intro.md b/docs/book/content/intro.md index 67db21e5..b9fb2cf0 100644 --- a/docs/book/content/intro.md +++ b/docs/book/content/intro.md @@ -22,4 +22,4 @@ Results will change as the underlying models improve. A fundamental reason for a ## Citing the Cost-of-Capital-Calculator Model -Cost-of-Capital-Calculator (Version 1.5.1)[Source code], https://github.com/PSLmodels/Cost-of-Capital-Calculator \ No newline at end of file +Cost-of-Capital-Calculator (Version 1.5.2)[Source code], https://github.com/PSLmodels/Cost-of-Capital-Calculator \ No newline at end of file diff --git a/setup.py b/setup.py index d37d1fe6..5cb0dd36 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ download_url="https://github.com/PSLmodels/Cost-of-Capital-Calculator", long_description_content_type="text/markdown", long_description=longdesc, - version="1.5.1", + version="1.5.2", license="CC0 1.0 Universal (CC0 1.0) Public Domain Dedication", packages=["ccc"], include_package_data=True, From a917b803dd01b999e63dc2859aa741356ccb9e04 Mon Sep 17 00:00:00 2001 From: jdebacker Date: Fri, 20 Sep 2024 22:33:27 -0400 Subject: [PATCH 9/9] update pypi publish action --- .github/workflows/create_pip_package.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/create_pip_package.yml b/.github/workflows/create_pip_package.yml index 28685319..b1a63654 100644 --- a/.github/workflows/create_pip_package.yml +++ b/.github/workflows/create_pip_package.yml @@ -12,11 +12,11 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repo - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: - python-version: 3.12 + python-version: "3.12" - name: Build package run: make pip-package - name: Publish a Python distribution to PyPI