Skip to content

Commit d915588

Browse files
committed
Explicit error for tolerance with older pandas
1 parent 986be9d commit d915588

File tree

5 files changed

+14
-0
lines changed

5 files changed

+14
-0
lines changed

ci/requirements-py26.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ dependencies:
1313
- unittest2
1414
- pip:
1515
- coveralls
16+
- cyordereddict
1617
- dask
1718
- h5netcdf

xray/core/alignment.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import functools
22
import operator
3+
import pandas as pd
34
from collections import defaultdict
45

56
import numpy as np
@@ -146,6 +147,9 @@ def reindex_variables(variables, indexes, indexers, method=None,
146147
# for compat with older versions of pandas that don't support tolerance
147148
get_indexer_kwargs = {}
148149
if tolerance is not None:
150+
if pd.__version__ < '0.17':
151+
raise NotImplementedError(
152+
'the tolerance argument requires pandas v0.17 or newer')
149153
get_indexer_kwargs['tolerance'] = tolerance
150154

151155
for name, index in iteritems(indexes):

xray/core/indexing.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ def convert_label_indexer(index, label, index_name='', method=None,
129129
if method is not None:
130130
kwargs['method'] = method
131131
if tolerance is not None:
132+
if pd.__version__ < '0.17':
133+
raise NotImplementedError(
134+
'the tolerance argument requires pandas v0.17 or newer')
132135
kwargs['tolerance'] = tolerance
133136

134137
if isinstance(label, slice):

xray/test/test_dataarray.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,9 @@ def test_sel_method(self):
396396
expected = data.sel(x=[1, 2])
397397
actual = data.sel(x=[0.9, 1.9], method='backfill', tolerance=1)
398398
self.assertDataArrayIdentical(expected, actual)
399+
else:
400+
with self.assertRaisesRegexp(NotImplementedError, 'tolerance'):
401+
data.sel(x=[0.9, 1.9], method='backfill', tolerance=1)
399402

400403
def test_isel_points(self):
401404
shape = (10, 5, 6)

xray/test/test_dataset.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,9 @@ def test_reindex_method(self):
861861
actual = ds.reindex(y=y, method='backfill', tolerance=0.1)
862862
expected = Dataset({'x': ('y', 3 * [np.nan]), 'y': y})
863863
self.assertDatasetIdentical(expected, actual)
864+
else:
865+
with self.assertRaisesRegexp(NotImplementedError, 'tolerance'):
866+
ds.reindex(y=y, method='backfill', tolerance=0.1)
864867

865868
actual = ds.reindex(y=y, method='pad')
866869
expected = Dataset({'x': ('y', [np.nan, 10, 20]), 'y': y})

0 commit comments

Comments
 (0)