Skip to content

Commit ee259ea

Browse files
phoflpmhatre1
authored andcommitted
REGR: shift raising for axis=1 and empty df (pandas-dev#57340)
1 parent 2b34374 commit ee259ea

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

doc/source/whatsnew/v2.2.1.rst

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Fixed regressions
2525
- Fixed regression in :meth:`DataFrame.groupby` raising ``ValueError`` when grouping by a :class:`Series` in some cases (:issue:`57276`)
2626
- Fixed regression in :meth:`DataFrame.loc` raising ``IndexError`` for non-unique, masked dtype indexes where result has more than 10,000 rows (:issue:`57027`)
2727
- Fixed regression in :meth:`DataFrame.merge` raising ``ValueError`` for certain types of 3rd-party extension arrays (:issue:`57316`)
28+
- Fixed regression in :meth:`DataFrame.shift` raising ``AssertionError`` for ``axis=1`` and empty :class:`DataFrame` (:issue:`57301`)
2829
- Fixed regression in :meth:`DataFrame.sort_index` not producing a stable sort for a index with duplicates (:issue:`57151`)
2930
- Fixed regression in :meth:`DataFrame.to_dict` with ``orient='list'`` and datetime or timedelta types returning integers (:issue:`54824`)
3031
- Fixed regression in :meth:`DataFrame.to_json` converting nullable integers to floats (:issue:`57224`)

pandas/core/frame.py

+3
Original file line numberDiff line numberDiff line change
@@ -5545,6 +5545,9 @@ def shift(
55455545
)
55465546
fill_value = lib.no_default
55475547

5548+
if self.empty:
5549+
return self.copy()
5550+
55485551
axis = self._get_axis_number(axis)
55495552

55505553
if is_list_like(periods):

pandas/tests/frame/methods/test_shift.py

+6
Original file line numberDiff line numberDiff line change
@@ -751,3 +751,9 @@ def test_shift_with_iterable_check_other_arguments(self):
751751
msg = "Cannot specify `suffix` if `periods` is an int."
752752
with pytest.raises(ValueError, match=msg):
753753
df.shift(1, suffix="fails")
754+
755+
def test_shift_axis_one_empty(self):
756+
# GH#57301
757+
df = DataFrame()
758+
result = df.shift(1, axis=1)
759+
tm.assert_frame_equal(result, df)

0 commit comments

Comments
 (0)