diff --git a/datareservoirio/client.py b/datareservoirio/client.py index 7e7ab839..92dfda54 100644 --- a/datareservoirio/client.py +++ b/datareservoirio/client.py @@ -49,7 +49,7 @@ def metric() -> logging.Logger: # Default values to push as start/end dates. (Limited by numpy.datetime64) _END_DEFAULT = 9214646400000000000 # 2262-01-01 -_START_DEFAULT = -9214560000000000000 # 1678-01-01 +_START_DEFAULT = 0 # 1970-01-01 _TIMEOUT_DEAULT = (120, 120) @@ -430,22 +430,16 @@ def get( else: df = pd.DataFrame(columns=("index", "values")).astype({"index": "int64"}) - try: - # When we move to pandas 3, the .loc here breaks with None start and end, haven't dug into why yet - series = ( - df.set_index("index").squeeze("columns").loc[start:end].copy(deep=True) - ) - except KeyError as e: + s = df.set_index("index").squeeze("columns") + + # Ensure sorted (cheap if already sorted) + if not s.index.is_monotonic_increasing: logging.warning( "The time series you requested is not properly ordered. The data will be sorted to attempt to resolve the issue. Please note that this operation may take some time." ) - series = ( - df.set_index("index") - .sort_index() - .squeeze("columns") - .loc[start:end] - .copy(deep=True) - ) + s = s.sort_index() + + series = s.loc[start:end] series.index.name = None if series.empty and raise_empty: # may become empty after slicing diff --git a/pyproject.toml b/pyproject.toml index 134f213c..d2349831 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,7 +22,7 @@ classifiers = [ dependencies = [ "numpy", "oauthlib", - "pandas < 3", + "pandas", "pyarrow", "requests", "requests-oauthlib", diff --git a/tests/response_cases.py b/tests/response_cases.py index c3cab62d..69663910 100644 --- a/tests/response_cases.py +++ b/tests/response_cases.py @@ -135,7 +135,7 @@ # description: TimeSeries API response (empty data) ( "GET", - "https://reservoir-api.4subsea.net/api/timeseries/e3d82cda-4737-4af9-8d17-d9dfda8703d0/data/days?start=-9214560000000000000&end=9214646399999999999", + "https://reservoir-api.4subsea.net/api/timeseries/e3d82cda-4737-4af9-8d17-d9dfda8703d0/data/days?start=0&end=9214646399999999999", ): { "_content": ( TEST_PATH @@ -489,7 +489,7 @@ # description: TimeSeries API response ( "GET", - "https://reservoir-api.4subsea.net/api/timeseries/2fee7f8a-664a-41c9-9b71-25090517c275/data/days?start=-9214560000000000000&end=9214646399999999999", + "https://reservoir-api.4subsea.net/api/timeseries/2fee7f8a-664a-41c9-9b71-25090517c275/data/days?start=0&end=9214646399999999999", ): { "status_code": 200, "reason": "OK", diff --git a/tests/test_client.py b/tests/test_client.py index 9b7b8094..6d5bffb9 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -140,10 +140,10 @@ def test_get(self, mock_requests, client, start, end, group1_data, response_case series_expect = group1_data.as_series() pd.testing.assert_series_equal(series_out, series_expect) # Check that the correct HTTP request is made - if start and end: + if start is not None and end is not None: request_url_expect = "https://reservoir-api.4subsea.net/api/timeseries/2fee7f8a-664a-41c9-9b71-25090517c275/data/days?start=1672358400000000000&end=1672703939999999999" else: - request_url_expect = "https://reservoir-api.4subsea.net/api/timeseries/2fee7f8a-664a-41c9-9b71-25090517c275/data/days?start=-9214560000000000000&end=9214646399999999999" + request_url_expect = "https://reservoir-api.4subsea.net/api/timeseries/2fee7f8a-664a-41c9-9b71-25090517c275/data/days?start=0&end=9214646399999999999" assert mock_requests.call_args_list[0].args[1] == request_url_expect def test_get_convert_date(self, client, group1_data, response_cases):