Skip to content

only use bottleneck version 1.0 and later #1190

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

Merged
merged 3 commits into from
Jan 7, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
move bottleneck version warning to Rolling.__init__
  • Loading branch information
Joe Hamman committed Dec 29, 2016
commit 2436defaf84cb9dce5eff22d4d65a672f05ffb25
7 changes: 3 additions & 4 deletions xarray/core/ops.py
Original file line number Diff line number Diff line change
@@ -18,10 +18,6 @@

try:
import bottleneck as bn
if StrictVersion(bn.__version__) < StrictVersion('1.0'):
warnings.warn('xarray requires bottleneck version of 1.0 or greater.'
'Falling back to numpy')
raise ImportError('Fall back to numpy')
has_bottleneck = True
except ImportError:
# use numpy methods instead
@@ -509,6 +505,9 @@ def inject_bottleneck_rolling_methods(cls):

# bottleneck rolling methods
if has_bottleneck:
if StrictVersion(bn.__version__) < StrictVersion('1.0'):
return

for bn_name, method_name in BOTTLENECK_ROLLING_METHODS.items():
f = getattr(bn, bn_name)
func = cls._bottleneck_reduce(f)
11 changes: 10 additions & 1 deletion xarray/core/rolling.py
Original file line number Diff line number Diff line change
@@ -2,11 +2,13 @@
from __future__ import division
from __future__ import print_function
import numpy as np
import warnings
from distutils.version import StrictVersion

from .pycompat import OrderedDict, zip
from .common import ImplementsRollingArrayReduce, full_like
from .combine import concat
from .ops import inject_bottleneck_rolling_methods
from .ops import inject_bottleneck_rolling_methods, has_bottleneck, bn


class Rolling(object):
@@ -48,6 +50,13 @@ def __init__(self, obj, min_periods=None, center=False, **windows):
rolling : type of input argument
"""

if (has_bottleneck and
(StrictVersion(bn.__version__) < StrictVersion('1.0'))):
warnings.warn('xarray requires bottleneck version of 1.0 or '
'greater for rolling operations. Rolling '
'aggregation methods will use numpy instead'
'of bottleneck.')

if len(windows) != 1:
raise ValueError('exactly one dim/window should be provided')

2 changes: 0 additions & 2 deletions xarray/test/__init__.py
Original file line number Diff line number Diff line change
@@ -70,8 +70,6 @@
try:
import bottleneck
if StrictVersion(bottleneck.__version__) < StrictVersion('1.0'):
warnings.warn('xarray requires bottleneck version of 1.0 or greater.'
'Falling back to numpy')
raise ImportError('Fall back to numpy')
has_bottleneck = True
except ImportError: