Skip to content
Open
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
18 changes: 18 additions & 0 deletions tests/test_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
14 changes: 12 additions & 2 deletions watttime/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Expand Down Expand Up @@ -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"
Expand Down
Loading