Skip to content

Commit

Permalink
Merge pull request #115 from jdebacker/remove_rpy2
Browse files Browse the repository at this point in the history
Merging
  • Loading branch information
rickecon authored Jun 11, 2024
2 parents e994433 + d7ee0fb commit acb734c
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 25 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,14 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.10", "3.11"]

steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Set up R ${{ matrix.r-version }}
uses: r-lib/actions/setup-r@v2
with:
r-version: release
- name: Setup Miniconda using Python ${{ matrix.python-version }}
uses: conda-incubator/setup-miniconda@v3
with:
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [0.1.10] - 2024-06-10 12:00:00

### Added

- Removes the `rpy2` dependency from the `environment.yml` and `setup.py` files, and modifies use of PSID data to avoid needing this package in OG-USA.


## [0.1.9] - 2024-06-07 12:00:00

### Added
Expand Down Expand Up @@ -111,6 +119,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0



[0.1.10]: https://github.com/PSLmodels/OG-USA/compare/v0.1.9...v0.1.10
[0.1.9]: https://github.com/PSLmodels/OG-USA/compare/v0.1.8...v0.1.9
[0.1.8]: https://github.com/PSLmodels/OG-USA/compare/v0.1.7...v0.1.8
[0.1.7]: https://github.com/PSLmodels/OG-USA/compare/v0.1.6...v0.1.7
Expand Down
3 changes: 2 additions & 1 deletion cs-config/cs_config/functions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ogusa
from ogusa.calibrate import Calibration
from ogcore.parameters import Specifications
from ogusa.constants import (
Expand Down Expand Up @@ -82,7 +83,7 @@ class MetaParams(paramtools.Parameters):


def get_version():
return "0.1.9"
return ogusa.__version__


def get_inputs(meta_param_dict):
Expand Down
Binary file not shown.
Binary file not shown.
3 changes: 2 additions & 1 deletion data/PSID/psid_download.R
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,5 @@ for (var in names(ind_var_names)){
print('Beginning to build panel')
# Build PSID panel
psid_df <- build.panel(datadir=mydir, fam.vars=famvars, ind.vars=indvars, sample="SRC", design='all')
save(psid_df,file=file.path(script.dir, 'psid1968to2017.RData'))

write.csv(psid_df, file=gzfile("psid1968to2017.csv.gz"))
1 change: 0 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ dependencies:
- black>=24.1.1
- pip
- pip:
- rpy2>=3.5.12
- openpyxl>=3.1.2
- cs-kit
- cs2tc
Expand Down
14 changes: 14 additions & 0 deletions ogusa/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
Specify what is available to import from the ogusa package.
"""

from ogusa.calibrate import *
from ogusa.bequest_transmission import *
from ogusa.get_micro_data import *
from ogusa.income import *
from ogusa.macro_params import *
from ogusa.transfer_distribution import *
from ogusa.utils import *
from ogusa.wealth import *

__version__ = "0.1.10"
17 changes: 4 additions & 13 deletions ogusa/psid_data_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,9 @@
from pandas_datareader import data as web
import datetime
from linearmodels import PanelOLS
from rpy2.robjects import r
from rpy2.robjects import conversion
from rpy2.robjects import default_converter
from rpy2.robjects import pandas2ri
from rpy2.robjects.packages import importr
from ogusa.constants import PSID_NOMINAL_VARS, PSID_CONSTANT_VARS


pandas2ri.activate()
pd.options.mode.chained_assignment = "raise"

try:
# This is the case when a separate script is calling this function in
# this module
Expand All @@ -29,7 +21,9 @@
os.makedirs(output_dir)


def prep_data(data="psid1968to2015.RData"):
def prep_data(
data=os.path.join(CURDIR, "..", "data", "PSID", "psid1968to2015.csv.gz")
):
"""
This script takes PSID data created from psid_download.R and:
1) Creates variables at the "tax filing unit" (equal to family
Expand All @@ -47,10 +41,7 @@ def prep_data(data="psid1968to2015.RData"):
income groups defined
"""
# Read data from R into pandas dataframe
r["load"](os.path.join(CURDIR, "..", "data", "PSID", data))
raw_r_df = r("psid_df")
with (default_converter + pandas2ri.converter).context():
raw_df = conversion.get_conversion().rpy2py(raw_r_df)
raw_df = pd.read_csv(data, compression="gzip")

# Create unique identifier for each household
# note that will define a new household if head or spouse changes
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="ogusa",
version="0.1.9",
version="0.1.10",
author="Jason DeBacker and Richard W. Evans",
license="CC0 1.0 Universal (CC0 1.0) Public Domain Dedication",
description="USA calibration for OG-Core",
Expand Down Expand Up @@ -37,7 +37,6 @@
"paramtools>=0.15.0",
"taxcalc>=3.0.0",
"requests",
"rpy2>=3.5.12",
"pandas-datareader",
"xlwt",
"openpyxl>=3.1.2",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from ogusa import utils
from ogusa.utils import read_cbo_forecast
import numpy as np


def test_read_cbo_forecast():
"""
Test that CBO data read as expected.
"""
test_df = utils.read_cbo_forecast()
test_df = read_cbo_forecast()

assert np.allclose(
test_df.loc[test_df["year"] == 2017, "Y"].values[0], 20344
Expand Down

0 comments on commit acb734c

Please sign in to comment.