Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible with pint unit registry configured with force_ndarray_like=True #1153

Closed
sguidara-ventus opened this issue Jan 4, 2024 · 2 comments

Comments

@sguidara-ventus
Copy link

sguidara-ventus commented Jan 4, 2024

Describe the bug
Querying station data fails when using a pint unit registry configured with force_ndarray_like=True.

To Reproduce
Running the following code raises an exception:

from datetime import datetime

import pint
from wetterdienst.provider.dwd.observation import (
    DwdObservationDataset,
    DwdObservationRequest,
    DwdObservationResolution,
)

ureg = pint.UnitRegistry(force_ndarray_like=True)
pint.set_application_registry(ureg)

request = DwdObservationRequest(
    parameter=DwdObservationDataset.WIND,
    resolution=DwdObservationResolution.HOURLY,
    start_date=datetime(2024, 1, 1, 0),
    end_date=datetime(2024, 1, 1, 3),
)
print(next(request.all().values.query()))

The exception is raised with traceback:

  File ".../example.py", line 23, in <module>
    print(next(request.all().values.query()))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../site-packages/wetterdienst/core/timeseries/values.py", line 443, in query
    station_df = self._convert_values_to_si(station_df, datasets)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../site-packages/wetterdienst/core/timeseries/values.py", line 232, in _convert_values_to_si
    group = group.with_columns(pl.col(Columns.VALUE.value).map_batches(lambda s, o=op, f=factor: o(s, f)))
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../site-packages/polars/dataframe/frame.py", line 8027, in with_columns
    return self.lazy().with_columns(*exprs, **named_exprs).collect(_eager=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../site-packages/polars/utils/deprecation.py", line 100, in wrapper
    return function(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../site-packages/polars/lazyframe/frame.py", line 1788, in collect
    return wrap_df(ldf.collect())
                   ^^^^^^^^^^^^^
polars.exceptions.ComputeError: TypeError: argument 'val': iteration over a 0-d array

Running the same code with force_ndarray_like=False runs just fine.

Expected behavior
Allow the querying of station data with a pint unit registry configured with force_ndarray_like=True.

Desktop (please complete the following information):

  • OS: Linux
  • Python-Version 3.11
  • polars version 0.19.19
  • wetterdienst version 0.71.0
  • pint version 0.22

Additional context
I've had to use the configuration force_ndarray_like=True because it is currently required if I want to use pint-xarray (see xarray-contrib/pint-xarray#216).

I realize this bug is not necessarily the responsibility of wetterdienst, but perhaps there exists an easy change in this project that would fix this issue.

@gutzbenj
Copy link
Member

Dear @sguidara-ventus ,

the latest release has a fix/workaround for this issue!

@sguidara-ventus
Copy link
Author

Thank you, this solved my issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants