Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update excepted rows for no-fips id-ed respondents but keep annualize… #3023

Merged
merged 3 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/pudl/output/ferc714.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,18 +652,20 @@ def summarized_demand_ferc714(
demand_hourly_pa_ferc714.loc[
:, ["report_date", "respondent_id_ferc714", "demand_mwh"]
],
on=["report_date", "respondent_id_ferc714"],
how="left",
)
.groupby(["report_date", "respondent_id_ferc714"])
.agg({"demand_mwh": sum})
.groupby(["report_date", "respondent_id_ferc714"], as_index=False)[
["demand_mwh"]
]
.sum(min_count=1)
.rename(columns={"demand_mwh": "demand_annual_mwh"})
.reset_index()
.merge(
georeferenced_counties_ferc714.groupby(
["report_date", "respondent_id_ferc714"]
)
.agg({"population": sum, "area_km2": sum})
.reset_index()
["report_date", "respondent_id_ferc714"], as_index=False
)[["population", "area_km2"]].sum(min_count=1),
on=["report_date", "respondent_id_ferc714"],
how="left",
zaneselvans marked this conversation as resolved.
Show resolved Hide resolved
)
.assign(
population_density_km2=lambda x: x.population / x.area_km2,
Expand Down
21 changes: 20 additions & 1 deletion test/validate/service_territory_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"df_name,expected_rows",
[
("summarized_demand_ferc714", 3_195),
zaneselvans marked this conversation as resolved.
Show resolved Hide resolved
("fipsified_respondents_ferc714", 135_627),
("fipsified_respondents_ferc714", 135_537),
("compiled_geometry_balancing_authority_eia861", 112_507),
("compiled_geometry_utility_eia861", 247_705),
],
Expand Down Expand Up @@ -46,3 +46,22 @@ def test_minmax_rows(
pv.check_max_rows, expected_rows=expected_rows, margin=0.0, df_name=df_name
)
)


def test_report_year_discrepency_in_demand_hourly_pa_ferc714(pudl_out_orig):
"""Test if the vast majority of the years in the two date columns line up."""
demand_hourly_pa_ferc714 = pudl_out_orig.demand_hourly_pa_ferc714()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will take a while to load ~15M rows from SQLite. If there's another test (or the transform) in which the table is already loaded, we might want to slip it in there rather than reading one of the longest tables multiple times.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it took one minute to run for me

(pudl-dev) [pudl] pytest test/validate/service_territory_test.py::test_report_year --live-dbs                 13:28:04ferc714_mystery_date_fix ☂ ⚡
================================================================== test session starts ==================================================================
platform darwin -- Python 3.11.6, pytest-7.4.3, pluggy-1.3.0 -- /Users/christinagosnell/miniforge3/envs/pudl-dev/bin/python
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase(PosixPath('/Users/christinagosnell/code/pudl/.hypothesis/examples'))
rootdir: /Users/christinagosnell/code/pudl
configfile: pyproject.toml
plugins: hypothesis-6.88.1, anyio-4.0.0, console-scripts-1.4.1, cov-4.1.0, mock-3.12.0, typeguard-4.1.5
collected 1 item

test/validate/service_territory_test.py::test_report_year
-------------------------------------------------------------------- live log setup ---------------------------------------------------------------------
2023-11-07 13:28:13 [    INFO] test.conftest:346 Starting unit tests with output path /Users/christinagosnell/code/pudl_work/output
2023-11-07 13:28:13 [    INFO] catalystcoop.pudl.workspace.setup:175 Skipping existing file at /Users/christinagosnell/code/pudl/src/pudl/package_data/settings/etl_full.yml
2023-11-07 13:28:13 [    INFO] catalystcoop.pudl.workspace.setup:175 Skipping existing file at /Users/christinagosnell/code/pudl/src/pudl/package_data/settings/etl_fast.yml
2023-11-07 13:28:14 [    INFO] alembic.runtime.migration:213 Context impl SQLiteImpl.
2023-11-07 13:28:14 [    INFO] alembic.runtime.migration:216 Will assume non-transactional DDL.
2023-11-07 13:28:14 [    INFO] alembic.runtime.migration:619 Running stamp_revision  -> ec80dd91891a
2023-11-07 13:28:14 [   DEBUG] alembic.runtime.migration:827 new branch insert ec80dd91891a
2023-11-07 13:28:14 [    INFO] alembic.runtime.migration:213 Context impl SQLiteImpl.
add report year validation test
2023-11-07 13:28:14 [    INFO] alembic.runtime.migration:216 Will assume non-transactional DDL.
2023-11-07 13:28:14 [    INFO] alembic.runtime.migration:619 Running stamp_revision  -> ec80dd91891a
2023-11-07 13:28:14 [   DEBUG] alembic.runtime.migration:827 new branch insert ec80dd91891a
2023-11-07 13:28:14 [    INFO] alembic.runtime.migration:213 Context impl SQLiteImpl.
2023-11-07 13:28:14 [    INFO] alembic.runtime.migration:216 Will assume non-transactional DDL.
2023-11-07 13:28:14 [    INFO] alembic.runtime.migration:619 Running stamp_revision  -> ec80dd91891a
2023-11-07 13:28:14 [   DEBUG] alembic.runtime.migration:827 new branch insert ec80dd91891a
2023-11-07 13:28:14 [    INFO] alembic.runtime.migration:213 Context impl SQLiteImpl.
2023-11-07 13:28:14 [    INFO] alembic.runtime.migration:216 Will assume non-transactional DDL.
2023-11-07 13:28:14 [    INFO] alembic.runtime.migration:619 Running stamp_revision  -> ec80dd91891a
2023-11-07 13:28:14 [   DEBUG] alembic.runtime.migration:827 new branch insert ec80dd91891a
2023-11-07 13:28:15 [    INFO] test.conftest:288 setting up the pudl_engine fixture
2023-11-07 13:28:15 [    INFO] alembic.runtime.migration:213 Context impl SQLiteImpl.
2023-11-07 13:28:15 [    INFO] alembic.runtime.migration:216 Will assume non-transactional DDL.
2023-11-07 13:28:15 [    INFO] alembic.runtime.migration:619 Running stamp_revision  -> ec80dd91891a
2023-11-07 13:28:15 [   DEBUG] alembic.runtime.migration:827 new branch insert ec80dd91891a
2023-11-07 13:28:15 [    INFO] alembic.runtime.migration:213 Context impl SQLiteImpl.
2023-11-07 13:28:15 [    INFO] alembic.runtime.migration:216 Will assume non-transactional DDL.
2023-11-07 13:28:15 [    INFO] alembic.runtime.migration:619 Running stamp_revision  -> ec80dd91891a
2023-11-07 13:28:15 [   DEBUG] alembic.runtime.migration:827 new branch insert ec80dd91891a
2023-11-07 13:28:15 [    INFO] alembic.runtime.migration:213 Context impl SQLiteImpl.
2023-11-07 13:28:15 [    INFO] alembic.runtime.migration:216 Will assume non-transactional DDL.
PASSED                                                                                                                                            [100%]

=================================================================== warnings summary ====================================================================
test/validate/service_territory_test.py::test_report_year
  /Users/christinagosnell/miniforge3/envs/pudl-dev/lib/python3.11/site-packages/dagster/_core/storage/sqlalchemy_compat.py:13: RemovedIn20Warning: Deprecated API features detected! These feature(s) are not compatible with SQLAlchemy 2.0. To prevent incompatible upgrades prior to updating applications, ensure requirements files are pinned to "sqlalchemy<2.0". Set environment variable SQLALCHEMY_WARN_20=1 to show all deprecation warnings.  Set environment variable SQLALCHEMY_SILENCE_UBER_WARNING=1 to silence this message. (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
    return db.select(items)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
======================================================== 1 passed, 1 warning in 83.09s (0:01:23) ========================================================

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i couuuuld add it into test_minmax_rows but that feels... wrong.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh hm there is currently no validation test for think chonker of a table. Since we are now loading it i can convert the test to check for both things.

mismatched_report_years = demand_hourly_pa_ferc714[
(
demand_hourly_pa_ferc714.utc_datetime.dt.year
!= demand_hourly_pa_ferc714.report_date.dt.year
)
]
if (
off_ratio := len(mismatched_report_years) / len(demand_hourly_pa_ferc714)
) > 0.001:
raise AssertionError(
f"Found more ({off_ratio:.2%}) than expected (>.1%) FERC714 records"
" where the report year from the utc_datetime differs from the "
"report_date column."
)
Loading