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 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/ccc/calcfunctions.py b/ccc/calcfunctions.py index 85cb492b..5179b68d 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 @@ -42,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" ] @@ -142,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) 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 ) 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( 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): """ 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]) diff --git a/ccc/utils.py b/ccc/utils.py index c8a30592..ec79bccc 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 @@ -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 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,