Skip to content

Commit ef4781c

Browse files
ESS-4162: Unpinning pandas (#150)
* Not using extremely low numbers that cause underflow and unpinning pandas * Forgot about the pyproject.toml change * Safer checking for None in test
1 parent 91c21e2 commit ef4781c

4 files changed

Lines changed: 13 additions & 19 deletions

File tree

datareservoirio/client.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def metric() -> logging.Logger:
4949

5050
# Default values to push as start/end dates. (Limited by numpy.datetime64)
5151
_END_DEFAULT = 9214646400000000000 # 2262-01-01
52-
_START_DEFAULT = -9214560000000000000 # 1678-01-01
52+
_START_DEFAULT = 0 # 1970-01-01
5353

5454
_TIMEOUT_DEAULT = (120, 120)
5555

@@ -430,22 +430,16 @@ def get(
430430
else:
431431
df = pd.DataFrame(columns=("index", "values")).astype({"index": "int64"})
432432

433-
try:
434-
# When we move to pandas 3, the .loc here breaks with None start and end, haven't dug into why yet
435-
series = (
436-
df.set_index("index").squeeze("columns").loc[start:end].copy(deep=True)
437-
)
438-
except KeyError as e:
433+
s = df.set_index("index").squeeze("columns")
434+
435+
# Ensure sorted (cheap if already sorted)
436+
if not s.index.is_monotonic_increasing:
439437
logging.warning(
440438
"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."
441439
)
442-
series = (
443-
df.set_index("index")
444-
.sort_index()
445-
.squeeze("columns")
446-
.loc[start:end]
447-
.copy(deep=True)
448-
)
440+
s = s.sort_index()
441+
442+
series = s.loc[start:end]
449443
series.index.name = None
450444

451445
if series.empty and raise_empty: # may become empty after slicing

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ classifiers = [
2222
dependencies = [
2323
"numpy",
2424
"oauthlib",
25-
"pandas < 3",
25+
"pandas",
2626
"pyarrow",
2727
"requests",
2828
"requests-oauthlib",

tests/response_cases.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
# description: TimeSeries API response (empty data)
136136
(
137137
"GET",
138-
"https://reservoir-api.4subsea.net/api/timeseries/e3d82cda-4737-4af9-8d17-d9dfda8703d0/data/days?start=-9214560000000000000&end=9214646399999999999",
138+
"https://reservoir-api.4subsea.net/api/timeseries/e3d82cda-4737-4af9-8d17-d9dfda8703d0/data/days?start=0&end=9214646399999999999",
139139
): {
140140
"_content": (
141141
TEST_PATH
@@ -489,7 +489,7 @@
489489
# description: TimeSeries API response
490490
(
491491
"GET",
492-
"https://reservoir-api.4subsea.net/api/timeseries/2fee7f8a-664a-41c9-9b71-25090517c275/data/days?start=-9214560000000000000&end=9214646399999999999",
492+
"https://reservoir-api.4subsea.net/api/timeseries/2fee7f8a-664a-41c9-9b71-25090517c275/data/days?start=0&end=9214646399999999999",
493493
): {
494494
"status_code": 200,
495495
"reason": "OK",

tests/test_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ def test_get(self, mock_requests, client, start, end, group1_data, response_case
140140
series_expect = group1_data.as_series()
141141
pd.testing.assert_series_equal(series_out, series_expect)
142142
# Check that the correct HTTP request is made
143-
if start and end:
143+
if start is not None and end is not None:
144144
request_url_expect = "https://reservoir-api.4subsea.net/api/timeseries/2fee7f8a-664a-41c9-9b71-25090517c275/data/days?start=1672358400000000000&end=1672703939999999999"
145145
else:
146-
request_url_expect = "https://reservoir-api.4subsea.net/api/timeseries/2fee7f8a-664a-41c9-9b71-25090517c275/data/days?start=-9214560000000000000&end=9214646399999999999"
146+
request_url_expect = "https://reservoir-api.4subsea.net/api/timeseries/2fee7f8a-664a-41c9-9b71-25090517c275/data/days?start=0&end=9214646399999999999"
147147
assert mock_requests.call_args_list[0].args[1] == request_url_expect
148148

149149
def test_get_convert_date(self, client, group1_data, response_cases):

0 commit comments

Comments
 (0)