earthobservations / wetterdienst

Open weather data for humans.
https://wetterdienst.readthedocs.io/
MIT License
358 stars 55 forks source link

MOSMIX Forecast: `ValueError: could not convert string to float: '55 1'` #846

Closed kumamt closed 1 year ago

kumamt commented 1 year ago
ERROR: ValueError: could not convert string to float: '55    1'

A bit detail about the code:

I have used the example code posted on the Wetterdienst Mosmix example section and it throws the same error. The code I wrote to extract information worked smoothly before and now it throws the error mentioned.

The Text Version :

Traceback (most recent call last):
  File "C:\Users\kumar\PycharmProjects\pythonProject\Mosmix_forecast.py", line 5, in <module>
    stations = DwdMosmixRequest(parameter="large", mosmix_type=DwdMosmixType.LARGE).filter_by_station_id(
  File "C:\Users\kumar\PycharmProjects\pythonProject\venv\lib\site-packages\wetterdienst\core\scalar\request.py", line 639, in filter_by_station_id
    df = self.all().df
  File "C:\Users\kumar\PycharmProjects\pythonProject\venv\lib\site-packages\wetterdienst\core\scalar\request.py", line 624, in all
    df = self._all().copy().reset_index(drop=True)
  File "C:\Users\kumar\PycharmProjects\pythonProject\venv\lib\site-packages\wetterdienst\provider\dwd\mosmix\api.py", line 529, in _all
    df[Columns.LATITUDE.value] = df[Columns.LATITUDE.value].astype(float).apply(convert_dm_to_dd)
  File "C:\Users\kumar\PycharmProjects\pythonProject\venv\lib\site-packages\pandas\core\generic.py", line 6240, in astype
    new_data = self._mgr.astype(dtype=dtype, copy=copy, errors=errors)
  File "C:\Users\kumar\PycharmProjects\pythonProject\venv\lib\site-packages\pandas\core\internals\managers.py", line 450, in astype
    return self.apply("astype", dtype=dtype, copy=copy, errors=errors)
  File "C:\Users\kumar\PycharmProjects\pythonProject\venv\lib\site-packages\pandas\core\internals\managers.py", line 352, in apply
    applied = getattr(b, f)(**kwargs)
  File "C:\Users\kumar\PycharmProjects\pythonProject\venv\lib\site-packages\pandas\core\internals\blocks.py", line 526, in astype
    new_values = astype_array_safe(values, dtype, copy=copy, errors=errors)
  File "C:\Users\kumar\PycharmProjects\pythonProject\venv\lib\site-packages\pandas\core\dtypes\astype.py", line 299, in astype_array_safe
    new_values = astype_array(values, dtype, copy=copy)
  File "C:\Users\kumar\PycharmProjects\pythonProject\venv\lib\site-packages\pandas\core\dtypes\astype.py", line 230, in astype_array
    values = astype_nansafe(values, dtype, copy=copy)
  File "C:\Users\kumar\PycharmProjects\pythonProject\venv\lib\site-packages\pandas\core\dtypes\astype.py", line 170, in astype_nansafe
    return arr.astype(dtype, copy=True)
ValueError: could not convert string to float: '55    1'

I have checked about the error and I think the value contains space and when we try to convert it to float, the program throws the error. Thank you so much for the response. Love the application and the work you guys have done. Helps a lot. Thank you

darian-heede commented 1 year ago

I can confirm this issue using the following:

docker run -i ghcr.io/earthobservations/wetterdienst-standard:0.51.0 \
  wetterdienst values \
  --provider=dwd \
  --network=mosmix \
  --resolution=small \
  --coordinates=50.78,6.083 \
  --rank=1 \
  --si-units=1 \
  --parameter=small
Mirko-Faber commented 1 year ago

I get the same issue for the line:

stations = request.filter_by_distance(latitude=52.30, longitude=8.92, distance=50)

image

amotl commented 1 year ago

Hi there,

thank you for writing in. We can confirm the error - thank you for the repro, @darian-heede. We are looking into the issue. Apparently, CI has observed this or a similar error once ^1. I think it will be some kind of glitch in the raw data.

With kind regards, Andreas.

amotl commented 1 year ago

Hi again. 0a46a50f7a has a quick patch [^patch], which fixes parsing the MOSMIX station list resource ^stations. It may have changed its format. At GH-847, we will have a corresponding discussion.

[^patch]: Also available in text format at mosmix-stations.patch.

gutzbenj commented 1 year ago

Dear all,

the latest release (0.52.0) has fixed it. Please try it out!

darian-heede commented 1 year ago

The fix in 0.52.0 works flawlessly. Thanks for the awesome work @amotl and @gutzbenj!

amotl commented 1 year ago

Excellent. Thanks for reporting back!

kumamt commented 1 year ago

Thank you so much @amotl and @gutzbenj for fixing the issue 👍🏽