Skip to content

Commit

Permalink
test and change: test was written to check if the timestamp for dataf…
Browse files Browse the repository at this point in the history
…rames(geoemtry) and geodataframes(groupByBoundary) is with timezone(UTC). Than the format parameter for every timestamp in the function _as_geodataframe was changed to ISO8601
  • Loading branch information
rp280 authored and SlowMo24 committed Nov 17, 2023
1 parent a3de2e7 commit 6a31938
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
10 changes: 5 additions & 5 deletions ohsome/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,30 +86,30 @@ def _as_geodataframe(self, multi_index=True):

if "@validFrom" in features.columns:
features["@validFrom"] = pd.to_datetime(
features["@validFrom"], format="%Y-%m-%dT%H:%M:%SZ"
features["@validFrom"], format="ISO8601"
)
features["@validTo"] = pd.to_datetime(
features["@validTo"], format="%Y-%m-%dT%H:%M:%SZ"
features["@validTo"], format="ISO8601"
)
if multi_index:
features = features.set_index(["@osmId", "@validFrom", "@validTo"])
elif "@snapshotTimestamp" in features.columns:
features["@snapshotTimestamp"] = pd.to_datetime(
features["@snapshotTimestamp"], format="%Y-%m-%dT%H:%M:%SZ"
features["@snapshotTimestamp"], format="ISO8601"
)
if multi_index:
features = features.set_index(["@osmId", "@snapshotTimestamp"])
elif (
"timestamp" in features.columns and "groupByBoundaryId" in features.columns
):
features["timestamp"] = pd.to_datetime(
features["timestamp"], format="%Y-%m-%dT%H:%M:%SZ"
features["timestamp"], format="ISO8601"
)
if multi_index:
features = features.set_index(["groupByBoundaryId", "timestamp"])
elif "@timestamp" in features.columns:
features["@timestamp"] = pd.to_datetime(
features["@timestamp"], format="%Y-%m-%dT%H:%M:%SZ"
features["@timestamp"], format="ISO8601"
)
if multi_index:
features = features.set_index(["@timestamp"])
Expand Down
7 changes: 3 additions & 4 deletions ohsome/test/test_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,8 @@ def test_empty_geodataframe(base_client):
assert result.empty


def test_check_timestamp_groupBy_boundary_and_geometry(base_client):
def test_check_timestamp_groupBy_boundary_and_geometry_for_user(base_client):
"""Tests whether the format of count.groupBy.Boundary is a timestamp format with timezone"""
input = dt.datetime(2008, 1, 1)

bbox = "8.67,49.39,8.71,49.42"
time = "2008-01-01/2023-01-01/P1Y"
Expand All @@ -383,5 +382,5 @@ def test_check_timestamp_groupBy_boundary_and_geometry(base_client):
)
result_geometry = response_geometry.as_dataframe().index.levels[1][0]

assert result_groupBy == input
assert result_geometry == input
assert result_groupBy.tz == dt.timezone.utc
assert result_geometry.tz == dt.timezone.utc

0 comments on commit 6a31938

Please sign in to comment.