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

Very minor but widespread formatting changes from ruff 0.3.0 #3445

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ repos:
# Formatters: hooks that re-write Python & documentation files
####################################################################################
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.2
rev: v0.3.0
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
1 change: 1 addition & 0 deletions devtools/print_requirements.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/python3
"""Print out install requirements from setup.py for use with pip install."""

import distutils.core

setup = distutils.core.run_setup("setup.py")
Expand Down
1 change: 1 addition & 0 deletions devtools/sqlite_to_duckdb.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#! /usr/bin/env python
"""A naive script for converting SQLite to DuckDB."""

import logging
from pathlib import Path

Expand Down
1 change: 1 addition & 0 deletions devtools/zenodo/zenodo_data_release.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
"""Script to sync a directory up to Zenodo."""

import datetime
import logging
import os
Expand Down
1 change: 1 addition & 0 deletions src/pudl/analysis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
rich library of tools that show how the data can be put to use. We may also generate
post-ETL derived database tables for distribution at some point.
"""

from . import (
allocate_gen_fuel,
epacamd_eia,
Expand Down
1 change: 1 addition & 0 deletions src/pudl/analysis/mcoe.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""A module with functions to aid generating MCOE."""

from typing import Literal

import pandas as pd
Expand Down
1 change: 1 addition & 0 deletions src/pudl/analysis/ml_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Implements shared tooling for machine learning models in PUDL."""

from . import models


Expand Down
1 change: 1 addition & 0 deletions src/pudl/analysis/ml_tools/experiment_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
to a file named 'experiments.sqlite' in the base directory of your PUDL repo, but
this is a configurable value, which can be found in the dagster UI.
"""

from collections.abc import Callable
from pathlib import Path

Expand Down
1 change: 1 addition & 0 deletions src/pudl/analysis/ml_tools/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
values can be edited here. This configuration will override both default values and
yaml configuration, but will only be used for a single run.
"""

import importlib

import yaml
Expand Down
1 change: 1 addition & 0 deletions src/pudl/analysis/plant_parts_eia.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
parts_compiler = MakePlantParts(pudl_out)
plant_parts_eia = parts_compiler.execute(gens_mega=gens_mega)
"""

from collections import OrderedDict
from copy import deepcopy
from importlib import resources
Expand Down
1 change: 1 addition & 0 deletions src/pudl/analysis/record_linkage/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This module implements models for various forms of record linkage."""

from . import (
classify_plants_ferc1,
eia_ferc1_model_config,
Expand Down
12 changes: 6 additions & 6 deletions src/pudl/analysis/record_linkage/eia_ferc1_record_linkage.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ def get_training_data_df(inputs):
)
train_df.loc[:, "source_dataset_r"] = "ferc_df"
train_df.loc[:, "source_dataset_l"] = "eia_df"
train_df.loc[
:, "clerical_match_score"
] = 1 # this column shows that all these labels are positive labels
train_df.loc[:, "clerical_match_score"] = (
1 # this column shows that all these labels are positive labels
)
return train_df


Expand Down Expand Up @@ -616,9 +616,9 @@ def override_bad_predictions(
override_df.loc[:, "match_type"] = "prediction; not in training data"
override_df.loc[override_rows, "match_type"] = "incorrect prediction; overwritten"
override_df.loc[correct_rows, "match_type"] = "correct match"
override_df.loc[
incorrect_rows, "match_type"
] = "incorrect prediction; no predicted match"
override_df.loc[incorrect_rows, "match_type"] = (
"incorrect prediction; no predicted match"
)
# print out stats
percent_correct = len(override_df[override_df.match_type == "correct match"]) / len(
train_df
Expand Down
6 changes: 3 additions & 3 deletions src/pudl/analysis/record_linkage/eia_ferc1_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ def _pct_diff(df, col) -> pd.DataFrame:
# Fed in the _pct_diff column so make sure it is neutral for this analysis
col = col.replace("_pct_diff", "")
# Fill in the _pct_diff column with the actual percent difference value
df.loc[
(df[f"{col}_eia"] > 0) & (df[f"{col}_ferc1"] > 0), f"{col}_pct_diff"
] = round(((df[f"{col}_ferc1"] - df[f"{col}_eia"]) / df[f"{col}_ferc1"] * 100), 2)
df.loc[(df[f"{col}_eia"] > 0) & (df[f"{col}_ferc1"] > 0), f"{col}_pct_diff"] = (
round(((df[f"{col}_ferc1"] - df[f"{col}_eia"]) / df[f"{col}_ferc1"] * 100), 2)
)

return df

Expand Down
7 changes: 4 additions & 3 deletions src/pudl/analysis/record_linkage/link_cross_year.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Define a record linkage model interface and implement common functionality."""

from pathlib import Path
from tempfile import TemporaryDirectory

Expand Down Expand Up @@ -61,9 +62,9 @@ def __init__(
year_inds = original_df.groupby("report_year").indices
for inds in year_inds.values():
matching_year_inds = np.array(np.meshgrid(inds, inds)).T.reshape(-1, 2)
self.distance_matrix[
matching_year_inds[:, 0], matching_year_inds[:, 1]
] = config.distance_penalty
self.distance_matrix[matching_year_inds[:, 0], matching_year_inds[:, 1]] = (
config.distance_penalty
)

np.fill_diagonal(self.distance_matrix, 0)
self.distance_matrix.flush()
Expand Down
1 change: 1 addition & 0 deletions src/pudl/analysis/service_territory.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
the historical spatial extent of utility and balancing area territories. Output the
resulting geometries for use in other applications.
"""

import math
import pathlib
import sys
Expand Down
1 change: 1 addition & 0 deletions src/pudl/analysis/spatial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Spatial operations for demand allocation."""

import itertools
import warnings
from collections.abc import Callable, Iterable
Expand Down
13 changes: 7 additions & 6 deletions src/pudl/analysis/state_demand.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Additional predictive spatial variables will be required to obtain more granular
electricity demand estimates (e.g. at the county level).
"""

import datetime
from collections.abc import Iterable
from typing import Any
Expand Down Expand Up @@ -280,9 +281,9 @@ def load_hourly_demand_matrix_ferc714(
of each `respondent_id_ferc714` and reporting `year` (int).
"""
# Convert UTC to local time (ignoring daylight savings)
out_ferc714__hourly_planning_area_demand[
"utc_offset"
] = out_ferc714__hourly_planning_area_demand["timezone"].map(STANDARD_UTC_OFFSETS)
out_ferc714__hourly_planning_area_demand["utc_offset"] = (
out_ferc714__hourly_planning_area_demand["timezone"].map(STANDARD_UTC_OFFSETS)
)
out_ferc714__hourly_planning_area_demand["datetime"] = utc_to_local(
out_ferc714__hourly_planning_area_demand["utc_datetime"],
out_ferc714__hourly_planning_area_demand["utc_offset"],
Expand All @@ -292,9 +293,9 @@ def load_hourly_demand_matrix_ferc714(
index="datetime", columns="respondent_id_ferc714", values="demand_mwh"
)
# List timezone by year for each respondent
out_ferc714__hourly_planning_area_demand[
"year"
] = out_ferc714__hourly_planning_area_demand["report_date"].dt.year
out_ferc714__hourly_planning_area_demand["year"] = (
out_ferc714__hourly_planning_area_demand["report_date"].dt.year
)
utc_offset = out_ferc714__hourly_planning_area_demand.groupby(
["respondent_id_ferc714", "year"], as_index=False
)["utc_offset"].first()
Expand Down
1 change: 1 addition & 0 deletions src/pudl/analysis/timeseries_cleaning.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* https://arxiv.org/abs/2008.03194
* https://github.com/xinychen/tensor-learning
"""

import functools
import warnings
from collections.abc import Iterable, Sequence
Expand Down
1 change: 1 addition & 0 deletions src/pudl/convert/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
to another, both independent of and within the context of the ETL pipeline.
This subpackage collects those tools together in one place.
"""

from . import (
censusdp1tract_to_sqlite,
metadata_to_rst,
Expand Down
1 change: 1 addition & 0 deletions src/pudl/etl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Dagster definitions for the PUDL ETL and Output tables."""

import importlib.resources
import itertools
import warnings
Expand Down
1 change: 1 addition & 0 deletions src/pudl/etl/check_foreign_keys.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Check that foreign key constraints in the PUDL database are respected."""

import pathlib
import sys

Expand Down
1 change: 1 addition & 0 deletions src/pudl/etl/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""A command line interface (CLI) to the main PUDL ETL functionality."""

import pathlib
import sys
from collections.abc import Callable
Expand Down
1 change: 1 addition & 0 deletions src/pudl/etl/eia_bulk_elec_assets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""EIA Bulk Electricty Aggregate assets."""

from dagster import asset

import pudl
Expand Down
1 change: 1 addition & 0 deletions src/pudl/etl/epacems_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
for processing each year of EPA CEMS data and execute these ops in parallel. For more information
see: https://docs.dagster.io/concepts/ops-jobs-graphs/dynamic-graphs and https://docs.dagster.io/concepts/assets/graph-backed-assets.
"""

from collections import namedtuple
from pathlib import Path

Expand Down
1 change: 1 addition & 0 deletions src/pudl/etl/glue_assets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""FERC and EIA and EPA CAMD glue assets."""

import networkx as nx
import pandas as pd
from dagster import AssetOut, Output, asset, multi_asset
Expand Down
7 changes: 4 additions & 3 deletions src/pudl/etl/static_assets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Dagster assets of static data tables."""

from typing import Literal

import pandas as pd
Expand Down Expand Up @@ -51,9 +52,9 @@ def static_pudl_tables(context):
dataset_settings = context.resources.dataset_settings

static_pudl_tables_dict = {"core_pudl__codes_subdivisions": POLITICAL_SUBDIVISIONS}
static_pudl_tables_dict[
"core_pudl__codes_datasources"
] = dataset_settings.make_datasources_table(ds)
static_pudl_tables_dict["core_pudl__codes_datasources"] = (
dataset_settings.make_datasources_table(ds)
)
return (
Output(output_name=table_name, value=df)
for table_name, df in static_pudl_tables_dict.items()
Expand Down
1 change: 1 addition & 0 deletions src/pudl/extract/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
are ready for normalization and data cleaning by the data source specific modules in the
:mod:`pudl.transform` subpackage.
"""

from . import (
eia176,
eia860,
Expand Down
1 change: 1 addition & 0 deletions src/pudl/extract/csv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Extractor for CSV data."""

from csv import DictReader
from importlib import resources
from zipfile import ZipFile
Expand Down
1 change: 1 addition & 0 deletions src/pudl/extract/dbf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Generalized DBF extractor for FERC data."""

import contextlib
import csv
import importlib.resources
Expand Down
1 change: 1 addition & 0 deletions src/pudl/extract/eia860.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

This code is for use analyzing EIA Form 860 data.
"""

import pandas as pd
from dagster import AssetOut, Output, multi_asset

Expand Down
1 change: 1 addition & 0 deletions src/pudl/extract/eia861.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

This code is for use analyzing EIA Form 861 data.
"""

import warnings

import pandas as pd
Expand Down
1 change: 1 addition & 0 deletions src/pudl/extract/eia923.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
This code is for use analyzing EIA Form 923 data. Currenly only years 2009-2016 work, as
they share nearly identical file formatting.
"""

import pandas as pd
from dagster import AssetOut, Output, multi_asset

Expand Down
1 change: 1 addition & 0 deletions src/pudl/extract/eia_bulk_elec.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
tables: one of metadata and one of timeseries. That is the format delivered by this
module.
"""

import warnings
from io import BytesIO
from pathlib import Path
Expand Down
10 changes: 7 additions & 3 deletions src/pudl/extract/epacems.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
Hence, we've called it `plant_id_epa` until it gets transformed into `plant_id_eia`
during the transform process with help from the crosswalk.
"""

from pathlib import Path
from typing import Annotated

Expand Down Expand Up @@ -173,9 +174,12 @@ def __init__(self, datastore: Datastore):

def get_data_frame(self, partition: EpaCemsPartition) -> pd.DataFrame:
"""Constructs dataframe from a zipfile for a given (year_quarter) partition."""
with self.datastore.get_zipfile_resource(
"epacems", **partition.get_filters()
) as zf, zf.open(str(partition.get_quarterly_file()), "r") as csv_file:
with (
self.datastore.get_zipfile_resource(
"epacems", **partition.get_filters()
) as zf,
zf.open(str(partition.get_quarterly_file()), "r") as csv_file,
):
df = self._csv_to_dataframe(
csv_file,
ignore_cols=API_IGNORE_COLS,
Expand Down
1 change: 1 addition & 0 deletions src/pudl/extract/excel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Load excel metadata CSV files form a python data package."""

import importlib.resources
import pathlib
import re
Expand Down
1 change: 0 additions & 1 deletion src/pudl/extract/ferc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Hooks to integrate ferc to sqlite functionality into dagster graph."""


import pudl
from pudl.extract.ferc1 import Ferc1DbfExtractor
from pudl.extract.ferc2 import Ferc2DbfExtractor
Expand Down
1 change: 1 addition & 0 deletions src/pudl/extract/ferc1.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@

https://data.catalyst.coop/ferc1
"""

import json
from itertools import chain
from pathlib import Path
Expand Down
8 changes: 5 additions & 3 deletions src/pudl/extract/ferc714.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Routines used for extracting the raw FERC 714 data."""

from collections import OrderedDict

import pandas as pd
Expand Down Expand Up @@ -84,9 +85,10 @@ def _extract_raw_ferc714(context):
logger.info(
f"Extracting {table_name} from CSV into pandas DataFrame (years: {years})."
)
with ds.get_zipfile_resource("ferc714", name="ferc714.zip") as zf, zf.open(
FERC714_FILES[table_name]["name"]
) as csv_file:
with (
ds.get_zipfile_resource("ferc714", name="ferc714.zip") as zf,
zf.open(FERC714_FILES[table_name]["name"]) as csv_file,
):
df = pd.read_csv(
csv_file,
encoding=FERC714_FILES[table_name]["encoding"],
Expand Down
1 change: 0 additions & 1 deletion src/pudl/extract/phmsagas.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
This modules pulls data from PHMSA's published Excel spreadsheets.
"""


import pandas as pd
from dagster import AssetOut, Output, multi_asset

Expand Down
1 change: 1 addition & 0 deletions src/pudl/extract/xbrl.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Generic extractor for all FERC XBRL data."""

import io
from collections.abc import Callable
from datetime import date
Expand Down
1 change: 1 addition & 0 deletions src/pudl/ferc_to_sqlite/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Dagster definitions for the FERC to SQLite process."""

import importlib.resources

from dagster import Definitions, graph
Expand Down
Loading
Loading