Skip to content

Commit 2056900

Browse files
jbrockmendelmathurk1tkmz-n
authored
BUG: BlockSlider not clearing index._cache (#35937)
* REF: remove unnecesary try/except * TST: add test for agg on ordered categorical cols (#35630) * TST: resample does not yield empty groups (#10603) (#35799) * revert accidental rebase * BUG: BlockSlider not clearing index._cache * update whatsnew Co-authored-by: Karthik Mathur <[email protected]> Co-authored-by: tkmz-n <[email protected]>
1 parent 075ed8b commit 2056900

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

doc/source/whatsnew/v1.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ Groupby/resample/rolling
256256
- Bug in :meth:`DataFrameGroupBy.apply` where a non-nuisance grouping column would be dropped from the output columns if another groupby method was called before ``.apply()`` (:issue:`34656`)
257257
- Bug in :meth:`DataFrameGroupby.apply` would drop a :class:`CategoricalIndex` when grouped on. (:issue:`35792`)
258258
- Bug when subsetting columns on a :class:`~pandas.core.groupby.DataFrameGroupBy` (e.g. ``df.groupby('a')[['b']])``) would reset the attributes ``axis``, ``dropna``, ``group_keys``, ``level``, ``mutated``, ``sort``, and ``squeeze`` to their default values. (:issue:`9959`)
259+
- Bug in :meth:`DataFrameGroupby.tshift` failing to raise ``ValueError`` when a frequency cannot be inferred for the index of a group (:issue:`35937`)
259260
-
260261

261262
Reshaping

pandas/_libs/reduction.pyx

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ cdef class _BaseGrouper:
5353
# to a 1-d ndarray like datetime / timedelta / period.
5454
object.__setattr__(cached_ityp, '_index_data', islider.buf)
5555
cached_ityp._engine.clear_mapping()
56+
cached_ityp._cache.clear() # e.g. inferred_freq must go
5657
object.__setattr__(cached_typ._mgr._block, 'values', vslider.buf)
5758
object.__setattr__(cached_typ._mgr._block, 'mgr_locs',
5859
slice(len(vslider.buf)))
@@ -71,6 +72,7 @@ cdef class _BaseGrouper:
7172
object res
7273

7374
cached_ityp._engine.clear_mapping()
75+
cached_ityp._cache.clear() # e.g. inferred_freq must go
7476
res = self.f(cached_typ)
7577
res = _extract_result(res)
7678
if not initialized:
@@ -455,6 +457,7 @@ cdef class BlockSlider:
455457

456458
object.__setattr__(self.index, '_index_data', self.idx_slider.buf)
457459
self.index._engine.clear_mapping()
460+
self.index._cache.clear() # e.g. inferred_freq must go
458461

459462
cdef reset(self):
460463
cdef:

pandas/tests/groupby/test_allowlist.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,6 @@ def test_groupby_selection_with_methods(df):
369369
"ffill",
370370
"bfill",
371371
"pct_change",
372-
"tshift",
373372
]
374373

375374
for m in methods:
@@ -379,6 +378,11 @@ def test_groupby_selection_with_methods(df):
379378
# should always be frames!
380379
tm.assert_frame_equal(res, exp)
381380

381+
# check that the index cache is cleared
382+
with pytest.raises(ValueError, match="Freq was not set in the index"):
383+
# GH#35937
384+
g.tshift()
385+
382386
# methods which aren't just .foo()
383387
tm.assert_frame_equal(g.fillna(0), g_exp.fillna(0))
384388
tm.assert_frame_equal(g.dtypes, g_exp.dtypes)

0 commit comments

Comments
 (0)