Skip to content

Commit a151f0f

Browse files
Brian TuBrian Tu
Brian Tu
authored and
Brian Tu
committed
Fix tests for CI, documentation
1 parent 91130bd commit a151f0f

File tree

7 files changed

+20
-15
lines changed

7 files changed

+20
-15
lines changed

doc/source/whatsnew/v0.21.0.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ Other Enhancements
130130
- `read_*` methods can now infer compression from non-string paths, such as ``pathlib.Path`` objects (:issue:`17206`).
131131
- :func:`pd.read_sas()` now recognizes much more of the most frequently used date (datetime) formats in SAS7BDAT files (:issue:`15871`).
132132
- :func:`DataFrame.items` and :func:`Series.items` is now present in both Python 2 and 3 and is lazy in all cases (:issue:`13918`, :issue:`17213`)
133-
- :func:`Series.reindex`, :func:`DataFrame.reindex`, :func:`Index.get_indexer` now support list-like argument for `tolerance`.
133+
- :func:`Series.reindex`, :func:`DataFrame.reindex`, :func:`Index.get_indexer` now support list-like argument for ``tolerance``.
134134

135135
.. _whatsnew_0210.api_breaking:
136136

pandas/core/generic.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2659,6 +2659,7 @@ def sort_index(self, axis=0, level=None, ascending=True, inplace=False,
26592659
Maximum distance between original and new labels for inexact
26602660
matches. The values of the index at the matching locations most
26612661
satisfy the equation ``abs(index[indexer] - target) <= tolerance``.
2662+
26622663
Tolerance may be a scalar value, which applies the same tolerance
26632664
to all values, or list-like, which applies variable tolerance per
26642665
element. List-like includes list, tuple, array, Series, and must be
@@ -2888,6 +2889,7 @@ def _reindex_multi(self, axes, copy, fill_value):
28882889
Maximum distance between original and new labels for inexact
28892890
matches. The values of the index at the matching locations most
28902891
satisfy the equation ``abs(index[indexer] - target) <= tolerance``.
2892+
28912893
Tolerance may be a scalar value, which applies the same tolerance
28922894
to all values, or list-like, which applies variable tolerance per
28932895
element. List-like includes list, tuple, array, Series, and must be

pandas/core/indexes/base.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2443,7 +2443,9 @@ def _get_unique_index(self, dropna=False):
24432443
tolerance : optional
24442444
Maximum distance from index value for inexact matches. The value of
24452445
the index at the matching location most satisfy the equation
2446-
``abs(index[loc] - key) <= tolerance``. Tolerance may be a scalar
2446+
``abs(index[loc] - key) <= tolerance``.
2447+
2448+
Tolerance may be a scalar
24472449
value, which applies the same tolerance to all values, or
24482450
list-like, which applies variable tolerance per element. List-like
24492451
includes list, tuple, array, Series, and must be the same size as
@@ -2570,6 +2572,7 @@ def _get_level_values(self, level):
25702572
Maximum distance between original and new labels for inexact
25712573
matches. The values of the index at the matching locations most
25722574
satisfy the equation ``abs(index[indexer] - target) <= tolerance``.
2575+
25732576
Tolerance may be a scalar value, which applies the same tolerance
25742577
to all values, or list-like, which applies variable tolerance per
25752578
element. List-like includes list, tuple, array, Series, and must be
@@ -2599,8 +2602,8 @@ def get_indexer(self, target, method=None, limit=None, tolerance=None):
25992602
if tolerance is not None:
26002603
tolerance = self._convert_tolerance(tolerance)
26012604
if isinstance(tolerance, np.ndarray) and \
2602-
target.size != tolerance.size and tolerance.size > 1:
2603-
raise ValueError('ndarray tolerance size must match '
2605+
target.size != len(tolerance) and len(tolerance) > 1:
2606+
raise ValueError('list-like tolerance size must match '
26042607
'target index size')
26052608

26062609
pself, ptarget = self._maybe_promote(target)

pandas/core/indexes/datetimes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,8 +1438,8 @@ def get_loc(self, key, method=None, tolerance=None):
14381438
except KeyError:
14391439
raise KeyError(key)
14401440
except ValueError as e:
1441-
# ndarray tolerance size must match target index size
1442-
if 'ndarray' in str(e):
1441+
# list-like tolerance size must match target index size
1442+
if 'list-like' in str(e):
14431443
raise e
14441444
raise KeyError(key)
14451445

pandas/core/indexes/period.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ def get_indexer(self, target, method=None, limit=None, tolerance=None):
782782
tolerance = self._convert_tolerance(tolerance)
783783
if isinstance(tolerance, np.ndarray) and \
784784
target.size != tolerance.size and tolerance.size > 1:
785-
raise ValueError('ndarray tolerance size must match '
785+
raise ValueError('list-like tolerance size must match '
786786
'target index size')
787787
return Index.get_indexer(self._int64index, target, method,
788788
limit, tolerance)

pandas/tests/indexes/datetimes/test_datetime.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ def test_get_indexer(self):
121121
tol_bad = [pd.Timedelta('2 hour').to_timedelta64(),
122122
pd.Timedelta('1 hour').to_timedelta64(),
123123
np.timedelta64(1, 'M'), ]
124-
with (pytest.raises(
125-
TypeError, match='All values.* convertible to \\[ns\\]'),
126-
pytest.warns(UserWarning)):
124+
with pytest.raises(
125+
TypeError, match='All values.* convertible to \\[ns\\]'),\
126+
pytest.warns(UserWarning):
127127
idx.get_indexer(target, 'nearest', tolerance=tol_bad)
128128
with pytest.raises(ValueError):
129129
idx.get_indexer(idx[[0]], method='nearest', tolerance='foo')

pandas/tests/indexes/period/test_period.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def test_get_loc(self):
9191
idx.get_loc('2000-01-10', method='nearest', tolerance='1 day')
9292
with pytest.raises(
9393
ValueError,
94-
match='ndarray tolerance size must match target index size'):
94+
match='list-like tolerance size must match target index size'):
9595
idx.get_loc('2000-01-10', method='nearest',
9696
tolerance=[pd.Timedelta('1 day').to_timedelta64(),
9797
pd.Timedelta('1 day').to_timedelta64()])
@@ -180,10 +180,10 @@ def test_get_indexer(self):
180180
tol_bad = [pd.Timedelta('2 hour').to_timedelta64(),
181181
pd.Timedelta('1 hour').to_timedelta64(),
182182
np.timedelta64(1, 'M'), ]
183-
with (pytest.raises(
184-
TypeError,
185-
match='All values.* convertible to \\[ns\\]'),
186-
pytest.warns(UserWarning)):
183+
with pytest.raises(
184+
TypeError,
185+
match='All values.* convertible to \\[ns\\]'),\
186+
pytest.warns(UserWarning):
187187
idx.get_indexer(target, 'nearest', tolerance=tol_bad)
188188
with pytest.raises(
189189
TypeError,

0 commit comments

Comments
 (0)