-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from noman404/noman404/issue#53
Implement dependent based output when they are provided closes #53 #94 #96 #97 #98 #99 #101 #54, #55, #57, #64, #67, #68, #69, #70, #71, #72, #73, #74, #77, #78, #82, #83, #84, #85, #86
- Loading branch information
Showing
16 changed files
with
1,033 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
from .core.input_mapper import import_single_household | ||
from .core.output_mapper import export_single_household | ||
from .core.input_mapper import generate_household | ||
from .core.output_mapper import export_household | ||
from .cli import main as cli | ||
|
||
__all__ = ["import_single_household", "export_single_household", "cli"] | ||
__all__ = ["generate_household", "export_household", "cli"] | ||
|
||
__version__ = "0.1.0" # Make sure this matches the version in pyproject.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import click | ||
import pandas as pd | ||
from pathlib import Path | ||
import sys | ||
import os | ||
|
||
|
||
# Delay imports until runtime | ||
def get_mappers(): | ||
from policyengine_taxsim.core.input_mapper import generate_household | ||
from policyengine_taxsim.core.output_mapper import export_household | ||
return generate_household, export_household | ||
|
||
|
||
def get_yaml_path(): | ||
"""Get the path to YAML whether running as script or frozen executable""" | ||
if getattr(sys, 'frozen', False): | ||
# Running in a bundle | ||
return os.path.join(sys._MEIPASS, "config", "variable_mappings.yaml") | ||
else: | ||
# Running in normal Python | ||
return os.path.join(Path(__file__).parent, "config", "variable_mappings.yaml") | ||
|
||
|
||
@click.command() | ||
@click.argument("input_file", type=click.Path(exists=True)) | ||
@click.option( | ||
"--output", | ||
"-o", | ||
type=click.Path(), | ||
default="output.csv", | ||
help="Output file path", | ||
) | ||
def main(input_file, output): | ||
""" | ||
Process TAXSIM input file and generate PolicyEngine-compatible output. | ||
""" | ||
try: | ||
# Get mapper functions at runtime | ||
import_single_household, export_single_household = get_mappers() | ||
|
||
# Read input file | ||
df = pd.read_csv(input_file) | ||
|
||
# Process each row | ||
results = [] | ||
for _, row in df.iterrows(): | ||
taxsim_input = row.to_dict() | ||
pe_situation = import_single_household(taxsim_input) | ||
taxsim_output = export_single_household(taxsim_input, pe_situation) | ||
results.append(taxsim_output) | ||
|
||
# Create output dataframe and save to csv | ||
output_df = pd.DataFrame(results) | ||
output_path = Path(output) | ||
output_path.parent.mkdir(parents=True, exist_ok=True) | ||
output_df.to_csv(output_path, index=False) | ||
click.echo(f"Output saved to {output}") | ||
except Exception as e: | ||
click.echo(f"Error processing input: {str(e)}", err=True) | ||
raise | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.