Skip to content

Commit de2ff74

Browse files
Not using extremely low numbers that cause underflow and unpinning pandas
1 parent 91c21e2 commit de2ff74

3 files changed

Lines changed: 11 additions & 17 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

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def test_get(self, mock_requests, client, start, end, group1_data, response_case
143143
if start and end:
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)