Skip to content

Commit

Permalink
Merge pull request #364 from jdebacker/auto_pub
Browse files Browse the repository at this point in the history
Pandas bug fix, add auto publish
  • Loading branch information
jdebacker authored Mar 30, 2022
2 parents e234baa + 48ef36b commit e4db0fb
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 627 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/create_pip_package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Publish package to PyPI
on:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]

publish:
needs: build
name: Publish to PyPI
if: github.repository == 'PSLmodels/Cost-of-Capital-Calculator'
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Build package
run: make pip-package
- name: Publish a Python distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: jdebacker
password: ${{ secrets.PYPI }}
skip_existing: true
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@ git-sync:
.PHONY=git-pr
git-pr:
@./gitpr $(N)

pip-package:
pip install wheel
python setup.py sdist bdist_wheel
28 changes: 12 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![codecov](https://codecov.io/gh/PSLmodels/Cost-of-Capital-Calculator/branch/master/graph/badge.svg?token=vOrtCdGu1c)](https://codecov.io/gh/PSLmodels/Cost-of-Capital-Calculator)

# Cost-of-Capital-Calculator
Cost-of-Capital-Calculator is a model that can be used to evaluate the effect of US federal taxes on the investment incentives of corporate and non-corporate businesses. Specifically, Cost-of-Capital-Calculator uses data on the business assets and financial policy, as well as microdata on individual tax filers, to compute marginal effective tax rates on new investments. In modeling the effects of changes to the individual income tax code, Cost-of-Capital-Calculator works with [Tax-Calculator](https://github.com/PSLmodels/tax-calculator), another open source model of US federal tax policy. Cost-of-Capital-Calculator is written in Python, an interpreted language that can execute on Windows, Mac, or Linux.
Cost-of-Capital-Calculator is a model that can be used to evaluate the effect of US federal taxes on the investment incentives of corporate and non-corporate businesses. Specifically, Cost-of-Capital-Calculator uses data on the business assets and financial policy, as well as microdata on individual tax filers, to compute marginal effective tax rates on new investments. In modeling the effects of changes to the individual income tax code, Cost-of-Capital-Calculator works with [Tax-Calculator](https://github.com/PSLmodels/tax-calculator), another open-source model of US federal tax policy. Cost-of-Capital-Calculator is written in Python, an interpreted language that can execute on Windows, Mac, or Linux.

## Installation

Expand All @@ -16,15 +16,17 @@ or with PyPI via:

```pip install cost-of-capital-calculator ```

## Disclaimer
Results will change as the underlying models improve. A fundamental reason for adopting open source methods in this project is so that people from all backgrounds can contribute to the models that our society uses to assess economic policy; when community-contributed improvements are incorporated, the model will produce different results.

## Web Application

## Using/contributing to Cost-of-Capital-Calculator
Cost-of-Capital-Calculator is available through a web
application, [Cost of Capital Calculator](https://compute.studio/PSLmodels/Cost-of-Capital-Calculator/). This app
allows you to generate estimates of marginal effective tax rates and the cost of capital
across production industries, type of asset, and separately for corporate and non-corporate
entities and different forms of financing. The web application is limited in that you cannot consider policy reforms to the individual income tax code.

There are two common ways to get started with Cost-of-Capital-Calculator:
## Contributing to Cost-of-Capital-Calculator

The **first way** to use Cost-of-Capital-Calculator is to download the source code and install the model on your machine. To do this, follow the following instructions:
To contribute to Cost-of-Capital-Calculator, you'll want to clone the GitHub repository to your own machine, where you can work with and edit the source code. To do this, follow the following instructions:
* Install the [Anaconda distribution](https://www.anaconda.com/distribution/) of Python
* Clone this repository to a directory on your computer
* From the terminal (or Conda command prompt), navigate to the directory to which you cloned this repository and run `conda env create -f environment.yml`
Expand All @@ -47,16 +49,10 @@ The **first way** to use Cost-of-Capital-Calculator is to download the source co

The CSV output files can be compared to the `./example_output/*_expected.csv` files that are checked into the repository to confirm that you are generating the expected output. The easiest way to do this is to use the `./example-diffs` command (or `example-diffs` on Windows). If you run into errors running the example script, please open a new issue in the Cost-of-Capital-Calculator repo with a description of the issue and any relevant tracebacks you receive.

As an alternative to the second and third steps above, one can download the `CCC` package directly from Anaconda with the command `conda install -c conda-forge ccc`.

## Disclaimer
Results will change as the underlying models improve. A fundamental reason for adopting open source methods in this project is so that people from all backgrounds can contribute to the models that our society uses to assess economic policy; when community-contributed improvements are incorporated, the model will produce different results.

The **second way** to use Cost-of-Capital-Calculator is through a web
application, [Cost of Capital Calculator](https://compute.studio/PSLmodels/Cost-of-Capital-Calculator/). This way
allows you to generate estimates of marginal effective tax rates and the cost of capital
across production industries, type of asset, and separately for corporate and non-corporate
entites and different forms of financing. The web application is limited in that you cannot consider policy reforms to the individual income tax code.

Of course, you can get started with Cost-of-Capital-Calculator both ways.

## Citing the Cost-of-Capital-Calculator Model
Cost-of-Capital-Calculator (Version 1.2.9)[Source code], https://github.com/PSLmodels/Cost-of-Capital-Calculator
Cost-of-Capital-Calculator (Version 1.2.10)[Source code], https://github.com/PSLmodels/Cost-of-Capital-Calculator
2 changes: 1 addition & 1 deletion ccc/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ def grouped_bar(self, calc, output_variable='mettr',
# Append dfs together so base policies in one
base_df['policy'] = 'Baseline'
reform_df['policy'] = 'Reform'
df = base_df.append(reform_df)
df = pd.concat([base_df, reform_df])
# Drop corporate or non-corporate per arguments
if corporate:
df.drop(df[df.tax_treat == 'non-corporate'].index,
Expand Down
14 changes: 9 additions & 5 deletions ccc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import json
import pandas as pd

PACKAGE_NAME = 'ccc'
PYPI_PACKAGE_NAME = 'cost-of-capital-calculator'

# Default year for model runs
DEFAULT_START_YEAR = 2022

Expand Down Expand Up @@ -55,7 +58,7 @@ def str_modified(i):

def diff_two_tables(df1, df2):
'''
Create the difference betweeen two dataframes.
Create the difference between two dataframes.
Args:
df1 (Pandas DataFrame): first DataFrame in difference
Expand Down Expand Up @@ -116,11 +119,12 @@ 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:
path_in_egg = os.path.join('ccc', fname)
vdf = pd.read_csv(
pkg_resources.resource_stream(
pkg_resources.Requirement.parse('ccc'),
pkg_resources.Requirement.parse(PYPI_PACKAGE_NAME),
path_in_egg),
index_col=index_col
)
Expand All @@ -143,10 +147,10 @@ def read_egg_json(fname):
'''
try:
path_in_egg = os.path.join('ccc', fname)
path_in_egg = os.path.join(PACKAGE_NAME, fname)
pdict = json.loads(
pkg_resources.resource_stream(
pkg_resources.Requirement.parse('ccc'),
pkg_resources.Requirement.parse(PYPI_PACKAGE_NAME),
path_in_egg).read().decode('utf-8'),
object_pairs_hook=OrderedDict
)
Expand Down
Loading

0 comments on commit e4db0fb

Please sign in to comment.