Xarray: Importing xarray fails if old version of bottleneck is installed

Created on 5 Dec 2017  Â·  5Comments  Â·  Source: pydata/xarray

Importing version 0.11 of xarray fails if version 1.0.0 of Bottleneck is installed.
Bottleneck seems to be an optional dependency of xarray. During runtime xarray replaces functions by their bottleneck versions if that is installed, but it does not check if the version of bottleneck that is installed is new enough to provide that function:

The getattr here fails with an AttributeError in this case:

https://github.com/pydata/xarray/blob/b46fcd656391d786b8d25b0615f6d4bd30b524b7/xarray/core/ops.py#L361-L365

AttributeError: 'module' object has no attribute 'move_argmax'

move_argmax was included into bottleneck in version 1.1.0, so if version 1.0 is installed this can't work.

I saw this on python2.7, but I don't think that should matter...

help wanted stale

Most helpful comment

All 5 comments

@aseyboldt - Xarray now has a minimum version requirement for bottleneck of 1.1. This is mentioned in the docs here: http://xarray.pydata.org/en/latest/installing.html#for-accelerating-xarray

@jhamman Ah, I didn't see that. In hindsight the install docs seem like an obvious place to look for info about this...

@maxim-lian That pandas solution would have saved me a bit of debugging :-)
I guess another option would be to only replace functions that are present in Bottleneck. As long as they only add and never change functions this would allow xarray to use even very recent additions to bottleneck.

~Also experiencing this, though for a different method & version of bottleneck:~

Sorry, turns out this was due to a Python 3.5 → 3.6 upgrade without re-install of pip packages. Please disregard!

$ pip list | grep -Ei "(bottleneck|xarray)"
Bottleneck                         1.2.1       
xarray                             0.10.1      
$ python3 -c "import xarray"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/khaeru/.local/lib/python3.6/site-packages/xarray/__init__.py", line 10, in <module>
    from .core.extensions import (register_dataarray_accessor,
  File "/home/khaeru/.local/lib/python3.6/site-packages/xarray/core/extensions.py", line 7, in <module>
    from .dataarray import DataArray
  File "/home/khaeru/.local/lib/python3.6/site-packages/xarray/core/dataarray.py", line 16, in <module>
    from . import rolling
  File "/home/khaeru/.local/lib/python3.6/site-packages/xarray/core/rolling.py", line 377, in <module>
    inject_bottleneck_rolling_methods(DataArrayRolling)
  File "/home/khaeru/.local/lib/python3.6/site-packages/xarray/core/ops.py", line 362, in inject_bottleneck_rolling_methods
    f = getattr(bn, bn_name)
AttributeError: module 'bottleneck' has no attribute 'move_sum'

In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity

If this issue remains relevant, please comment here or remove the stale label; otherwise it will be marked as closed automatically

Was this page helpful?
0 / 5 - 0 ratings