Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions datareservoirio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
branislav-jenco-4ss marked this conversation as resolved.

Comment thread
branislav-jenco-4ss marked this conversation as resolved.
_TIMEOUT_DEAULT = (120, 120)

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ classifiers = [
dependencies = [
"numpy",
"oauthlib",
"pandas < 3",
"pandas",
"pyarrow",
"requests",
"requests-oauthlib",
Expand Down
4 changes: 2 additions & 2 deletions tests/response_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading