From 12e6bd082b0085728eb84398cb5eedc9bee6fff7 Mon Sep 17 00:00:00 2001 From: geoffhancock Date: Tue, 1 Sep 2026 14:53:03 -0400 Subject: [PATCH] Fix include_imputed_marker being passed as include_meta in get_historical_csv get_historical_csv passed include_imputed_marker as the sixth positional argument to get_historical_pandas, whose sixth parameter is include_meta. As a result, get_historical_csv(..., include_imputed_marker=True) wrote a CSV containing a meta column and no imputed_data_used column. Pass all defaulted parameters by keyword in the internal call chain (get_historical_csv -> get_historical_pandas -> get_historical_jsons) so argument order differences between signatures cannot misroute a flag. Public signatures are unchanged. Adds a regression test asserting the CSV contains imputed_data_used and not meta when include_imputed_marker=True. Co-Authored-By: Claude Fable 5 --- tests/test_sdk.py | 18 ++++++++++++++++++ watttime/api.py | 14 ++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/tests/test_sdk.py b/tests/test_sdk.py index 8721012..4a2a298 100644 --- a/tests/test_sdk.py +++ b/tests/test_sdk.py @@ -262,6 +262,24 @@ def test_get_historical_csv(self): assert fp.exists() fp.unlink() + def test_get_historical_csv_include_imputed(self): + start = parse("2025-01-01 00:00Z") + end = parse("2025-01-02 00:00Z") + self.historical.get_historical_csv( + start, end, REGION, include_imputed_marker=True + ) + + fp = ( + Path.home() + / "watttime_historical_csvs" + / f"{REGION}_co2_moer_{start.date()}_{end.date()}.csv" + ) + assert fp.exists() + df = pd.read_csv(fp) + self.assertIn("imputed_data_used", df.columns) + self.assertNotIn("meta", df.columns) + fp.unlink() + def test_multi_model_range(self): """If model is not specified, we should only return the most recent model data""" myaccess = WattTimeMyAccess() diff --git a/watttime/api.py b/watttime/api.py index 2609894..2808d24 100644 --- a/watttime/api.py +++ b/watttime/api.py @@ -454,7 +454,12 @@ def get_historical_pandas( pd.DataFrame: _description_ """ responses = self.get_historical_jsons( - start, end, region, signal_type, model, include_imputed_marker + start, + end, + region, + signal_type=signal_type, + model=model, + include_imputed_marker=include_imputed_marker, ) df = pd.json_normalize( responses, record_path="data", meta=["meta"] if include_meta else [] @@ -490,7 +495,12 @@ def get_historical_csv( None, results are saved to a csv file in the user's home directory. """ df = self.get_historical_pandas( - start, end, region, signal_type, model, include_imputed_marker + start, + end, + region, + signal_type=signal_type, + model=model, + include_imputed_marker=include_imputed_marker, ) out_dir = Path.home() / "watttime_historical_csvs"