From de2ff742ad48182b18f94a20b3c463107cc8dad1 Mon Sep 17 00:00:00 2001 From: branislav-jenco-4ss <152614622+branislav-jenco-4ss@users.noreply.github.com> Date: Thu, 21 May 2026 08:33:11 +0200 Subject: [PATCH 1/3] Not using extremely low numbers that cause underflow and unpinning pandas --- datareservoirio/client.py | 22 ++++++++-------------- tests/response_cases.py | 4 ++-- tests/test_client.py | 2 +- 3 files changed, 11 insertions(+), 17 deletions(-) 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/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..32823ac5 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -143,7 +143,7 @@ def test_get(self, mock_requests, client, start, end, group1_data, response_case if start and end: 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): From f23654b178093dcb7966d4633f5be46a913d43de Mon Sep 17 00:00:00 2001 From: branislav-jenco-4ss <152614622+branislav-jenco-4ss@users.noreply.github.com> Date: Thu, 21 May 2026 08:43:32 +0200 Subject: [PATCH 2/3] Forgot about the pyproject.toml change --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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", From d1522404fb745943e6fd259a56b6caf295dd30fc Mon Sep 17 00:00:00 2001 From: branislav-jenco-4ss <152614622+branislav-jenco-4ss@users.noreply.github.com> Date: Thu, 21 May 2026 08:44:55 +0200 Subject: [PATCH 3/3] Safer checking for None in test --- tests/test_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_client.py b/tests/test_client.py index 32823ac5..6d5bffb9 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -140,7 +140,7 @@ 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=0&end=9214646399999999999"