earthobservations / wetterdienst

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

Running command line examples (and others) fails with polars.exceptions.ComputeError: conversion from `str` to `f64` failed in column 'height' #1295

Closed asmod3us closed 3 weeks ago

asmod3us commented 2 months ago

Describe the bug Reading through https://wetterdienst.readthedocs.io/en/latest/usage/cli.html, I attempted a few commands. E.g.

wetterdienst stations --provider=dwd --network=observation --parameter=kl --resolution=daily --all

Fails with

2024-05-14 22:33:28,123 [wetterdienst.settings                   ] INFO   : Wetterdienst cache is enabled [CACHE_DIR: /Users/asmodeus/Library/Caches/wetterdienst]
2024-05-14 22:33:28,124 [wetterdienst.core.timeseries.request    ] INFO   : Processing request DwdObservationRequest(parameter=[(kl/kl)], resolution=daily, period=[None], start_date=None, end_date=None, humanize=False, format=long, si_units=False)
2024-05-14 22:33:28,124 [wetterdienst.provider.dwd.observation.api] WARNING: The combination of kl, daily, now is invalid.
2024-05-14 22:33:28,136 [wetterdienst.util.network               ] INFO   : Creating dircache folder at /Users/asmodeus/Library/Caches/wetterdienst/43200.0
2024-05-14 22:33:28,144 [wetterdienst.provider.dwd.observation.metaindex] INFO   : Downloading file https://opendata.dwd.de/climate_environment/CDC/observations_germany/climate//daily/kl/recent/KL_Tageswerte_Beschreibung_Stationen.txt.
2024-05-14 22:33:28,144 [wetterdienst.util.network               ] INFO   : Creating dircache folder at /Users/asmodeus/Library/Caches/wetterdienst-fsspec/None
2024-05-14 22:33:28,184 [wetterdienst.provider.dwd.observation.metaindex] INFO   : Downloading file https://opendata.dwd.de/climate_environment/CDC/observations_germany/climate//daily/kl/historical/KL_Tageswerte_Beschreibung_Stationen.txt.
Traceback (most recent call last):
  File "/Users/asmodeus/.cache/direnv/layouts/wetterdienst-70fa53e/python-3.12/bin/wetterdienst", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/Users/asmodeus/.cache/direnv/layouts/wetterdienst-70fa53e/python-3.12/lib/python3.12/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/asmodeus/.cache/direnv/layouts/wetterdienst-70fa53e/python-3.12/lib/python3.12/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Users/asmodeus/.cache/direnv/layouts/wetterdienst-70fa53e/python-3.12/lib/python3.12/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/asmodeus/.cache/direnv/layouts/wetterdienst-70fa53e/python-3.12/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/asmodeus/.cache/direnv/layouts/wetterdienst-70fa53e/python-3.12/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/asmodeus/.cache/direnv/layouts/wetterdienst-70fa53e/python-3.12/lib/python3.12/site-packages/wetterdienst/ui/cli.py", line 767, in stations
    stations_ = get_stations(
                ^^^^^^^^^^^^^
  File "/Users/asmodeus/.cache/direnv/layouts/wetterdienst-70fa53e/python-3.12/lib/python3.12/site-packages/wetterdienst/ui/core.py", line 189, in get_stations
    return r.all()
           ^^^^^^^
  File "/Users/asmodeus/.cache/direnv/layouts/wetterdienst-70fa53e/python-3.12/lib/python3.12/site-packages/wetterdienst/core/timeseries/request.py", line 633, in all
    df = df.collect()
         ^^^^^^^^^^^^
  File "/Users/asmodeus/.cache/direnv/layouts/wetterdienst-70fa53e/python-3.12/lib/python3.12/site-packages/polars/lazyframe/frame.py", line 1816, in collect
    return wrap_df(ldf.collect(callback))
                   ^^^^^^^^^^^^^^^^^^^^^
polars.exceptions.ComputeError: conversion from `str` to `f64` failed in column 'height' for 643 out of 1361 values: ["53.6623   1", "48.8443   1", … "50.9625   1"]

To Reproduce Python 3.12.3, fresh pip install wetterdienst in a new venv.

Expected behavior A list of stations as JSON :)

Desktop (please complete the following information):

Additional context I attempted to run a few other Command Line examples and got the same error. The streamlit app also seems to have issues, and other (previously working) programs using wetterdienst exhibit the same behaviour. Could this be a backend issue / change in data format? I noticed #1272 talks about a similar error:

I couldn't reproduce this problem in my personal Notebook but got this problem instead: error | "conversion from str to f64 failed in column 'height' for 519 out of 519 values: ["30429 20110331", "70209 20240423", … "30401 20240424"]"

LalonSander commented 2 months ago

We're having the same issue. It seems to be similar to issue 1277

The stations list was updated again on May 14 and the column labels and data below seem to be misaligned: https://opendata.dwd.de/climate_environment/CDC/observations_germany/climate/daily/kl/recent/

pwrtux commented 2 months ago

Same problem here

gutzbenj commented 2 months ago

Oh wow, there's now a complete chaos amongst all station lists :/ will try to find a solution asap

LalonSander commented 2 months ago

@gutzbenj: You probably have a way better grasp on parsing the lists. My solution would be something like replacing whitespace in the Text with commas and then treating the lists as csv

gutzbenj commented 2 months ago

@LalonSander I think it is not as simple as that because there are some station names with one or more whitespaces and commas in it. But nonetheless I will try my best to build a more sustainable (and similarly fast) solution.

gutzbenj commented 2 months ago

New version should have fixed it, please give it a try!

asmod3us commented 2 months ago

Confirmed working again! Thanks @gutzbenj for the quick fix 👍 I had to delete the cache at ~/Library/Caches/wetterdienst to get going again.

LalonSander commented 2 months ago

We're up and running again, thnsk for the quick fix!

pwrtux commented 2 months ago

Yes it works, thx for the fix!

jamaa commented 2 months ago

Can we persuade the DWD somehow to format its files such that they are more easily machine-readable? This has really bugged me multiple times. If they would at least use a separator other than space, it would make life so much easier, not only for wetterdienst

gutzbenj commented 2 months ago

As @jeremiahpslewis once said: The DWDs most important task here is to make the data available and we (private entities) are there to provide the data even nicer. Still though some normal separator would be nice :D