GIScience / ohsome-py

Python bindings for the ohsome API
GNU General Public License v3.0
18 stars 4 forks source link

as_dataframe() panda error #112

Closed ManuelKraft closed 1 year ago

ManuelKraft commented 1 year ago

I have the following small script:

from ohsome import OhsomeClient

client = OhsomeClient()
time = "2018-01-01"
request = client.elements.count.post(
    bpolys = '8.65821,49.41129,8.65821,49.41825,8.70053,49.41825,8.70053,49.41129,8.65821,49.41129', 
    filter = "building = yes", 
    time = time
)
print(request.data)
print(request.as_dataframe())
Traceback (most recent call last):
  File "tests.py", line 12, in <module>
    print(request.as_dataframe())
  File "/home/mkraft/miniconda3/envs/ohsome/lib/python3.8/site-packages/ohsome/response.py", line 30, in as_dataframe
    return self._as_dataframe(multi_index)
  File "/home/mkraft/miniconda3/envs/ohsome/lib/python3.8/site-packages/ohsome/response.py", line 61, in _as_dataframe
    self._format_timestamp(result_df)
  File "/home/mkraft/miniconda3/envs/ohsome/lib/python3.8/site-packages/ohsome/response.py", line 172, in _format_timestamp
    result_df["timestamp"] = pd.to_datetime(
  File "/home/mkraft/.local/lib/python3.8/site-packages/pandas/core/tools/datetimes.py", line 1050, in to_datetime
    values = convert_listlike(arg._values, format)
  File "/home/mkraft/.local/lib/python3.8/site-packages/pandas/core/tools/datetimes.py", line 453, in _convert_listlike_datetimes
    return _array_strptime_with_fallback(arg, name, utc, format, exact, errors)
  File "/home/mkraft/.local/lib/python3.8/site-packages/pandas/core/tools/datetimes.py", line 484, in _array_strptime_with_fallback
    result, timezones = array_strptime(arg, fmt, exact=exact, errors=errors, utc=utc)
  File "pandas/_libs/tslibs/strptime.pyx", line 530, in pandas._libs.tslibs.strptime.array_strptime
  File "pandas/_libs/tslibs/strptime.pyx", line 355, in pandas._libs.tslibs.strptime.array_strptime
ValueError: unconverted data remains when parsing with format "%Y-%m-%dT%H:%M:%S": "Z", at position 0. You might want to try:
    - passing `format` if your strings have a consistent format;
    - passing `format='ISO8601'` if your strings are all ISO8601 but not necessarily in exactly the same format;
    - passing `format='mixed'`, and the format will be inferred for each element individually. You might want to use `dayfirst` alongside this.

My panda Version is 1.5.3. The problem also happens in 1.5.2. It also happens with groupByBoundary-post-request. 2 Months ago this error did not happen.

Thanks for inspecting, Manuel

johanngrobe commented 1 year ago

I have the same issue. Is there any fix yet?

redfrexx commented 1 year ago

Thanks for reporting! We'll have a look at it next week.