Skip to content

Commit 413eba4

Browse files
authored
BUG: reindex raising TypeError with timezone aware index and tolerance for ffill and bfill (#39095)
1 parent d9ae308 commit 413eba4

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

doc/source/whatsnew/v1.3.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ Indexing
247247
- Bug in :meth:`CategoricalIndex.get_indexer` failing to raise ``InvalidIndexError`` when non-unique (:issue:`38372`)
248248
- Bug in inserting many new columns into a :class:`DataFrame` causing incorrect subsequent indexing behavior (:issue:`38380`)
249249
- Bug in :meth:`DataFrame.loc`, :meth:`Series.loc`, :meth:`DataFrame.__getitem__` and :meth:`Series.__getitem__` returning incorrect elements for non-monotonic :class:`DatetimeIndex` for string slices (:issue:`33146`)
250+
- Bug in :meth:`DataFrame.reindex` and :meth:`Series.reindex` with timezone aware indexes raising ``TypeError`` for ``method="ffill"`` and ``method="bfill"`` and specified ``tolerance`` (:issue:`38566`)
250251
- Bug in :meth:`DataFrame.__setitem__` raising ``ValueError`` with empty :class:`DataFrame` and specified columns for string indexer and non empty :class:`DataFrame` to set (:issue:`38831`)
251252
- Bug in :meth:`DataFrame.iloc.__setitem__` and :meth:`DataFrame.loc.__setitem__` with mixed dtypes when setting with a dictionary value (:issue:`38335`)
252253
- Bug in :meth:`DataFrame.loc` dropping levels of :class:`MultiIndex` when :class:`DataFrame` used as input has only one row (:issue:`10521`)

pandas/core/indexes/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3378,7 +3378,7 @@ def _get_fill_indexer(
33783378
else:
33793379
indexer = self._get_fill_indexer_searchsorted(target, method, limit)
33803380
if tolerance is not None and len(self):
3381-
indexer = self._filter_indexer_tolerance(target_values, indexer, tolerance)
3381+
indexer = self._filter_indexer_tolerance(target._values, indexer, tolerance)
33823382
return indexer
33833383

33843384
@final

pandas/tests/frame/methods/test_reindex.py

+15
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,21 @@ def test_reindex_frame_add_nat(self):
177177
assert mask[-5:].all()
178178
assert not mask[:-5].any()
179179

180+
@pytest.mark.parametrize(
181+
"method, exp_values",
182+
[("ffill", [0, 1, 2, 3]), ("bfill", [1.0, 2.0, 3.0, np.nan])],
183+
)
184+
def test_reindex_frame_tz_ffill_bfill(self, frame_or_series, method, exp_values):
185+
# GH#38566
186+
obj = frame_or_series(
187+
[0, 1, 2, 3],
188+
index=date_range("2020-01-01 00:00:00", periods=4, freq="H", tz="UTC"),
189+
)
190+
new_index = date_range("2020-01-01 00:01:00", periods=4, freq="H", tz="UTC")
191+
result = obj.reindex(new_index, method=method, tolerance=pd.Timedelta("1 hour"))
192+
expected = frame_or_series(exp_values, index=new_index)
193+
tm.assert_equal(result, expected)
194+
180195
def test_reindex_limit(self):
181196
# GH 28631
182197
data = [["A", "A", "A"], ["B", "B", "B"], ["C", "C", "C"], ["D", "D", "D"]]

0 commit comments

Comments
 (0)