From 0388ace90bf3292cd607bd72e25d1fcc9a848ccb Mon Sep 17 00:00:00 2001 From: Victor Ramirez Date: Wed, 18 Sep 2024 16:07:18 +0000 Subject: [PATCH] PLAT-1221 Fix parallel end_time when undefine This MR fixes the end_time bound for parallelization when undefined. Previously it uses the user's timezone but it should be UTC --- coinmetrics/_data_collection.py | 2 +- test/test_parallel_datacollections.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/coinmetrics/_data_collection.py b/coinmetrics/_data_collection.py index 6394648..54f811d 100644 --- a/coinmetrics/_data_collection.py +++ b/coinmetrics/_data_collection.py @@ -640,7 +640,7 @@ def generate_ranges( end_time = self.parse_date( cast(datetime, self._url_params.get("end_time")) ) if self._url_params.get( - "end_time") else datetime.today() + "end_time") else datetime.utcnow().replace(microsecond=0) for start, end in generate_ranges( start_time, end_time, diff --git a/test/test_parallel_datacollections.py b/test/test_parallel_datacollections.py index 5e03edd..51e7f82 100644 --- a/test/test_parallel_datacollections.py +++ b/test/test_parallel_datacollections.py @@ -291,6 +291,19 @@ def test_height_increment() -> None: end_inclusive=False ).parallel(height_increment=10).to_dataframe() assert len(df_blocks) == 90 + + +@pytest.mark.skipif(not cm_api_key_set, reason=REASON_TO_SKIP) +def test_end_time_undefined() -> None: + start_time = datetime.datetime.utcnow().replace(microsecond=0, second=0) - timedelta(minutes=60) + df_metrics_1m = client.get_asset_metrics( + assets='btc', + metrics='ReferenceRateUSD', + start_time=start_time, + frequency='1m' + ).parallel(time_increment=timedelta(minutes=1)).to_dataframe() + assert not df_metrics_1m.empty + assert df_metrics_1m.time.min().to_pydatetime().replace(tzinfo=None) == start_time if __name__ == '__main__':