Skip to content

Commit b6099b9

Browse files
phoflmeeseeksmachine
authored andcommitted
Backport PR pandas-dev#57340: REGR: shift raising for axis=1 and empty df
1 parent 947f5ae commit b6099b9

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
@@ -24,6 +24,7 @@ Fixed regressions
2424
- Fixed regression in :meth:`DataFrame.groupby` raising ``ValueError`` when grouping by a :class:`Series` in some cases (:issue:`57276`)
2525
- Fixed regression in :meth:`DataFrame.loc` raising ``IndexError`` for non-unique, masked dtype indexes where result has more than 10,000 rows (:issue:`57027`)
2626
- Fixed regression in :meth:`DataFrame.merge` raising ``ValueError`` for certain types of 3rd-party extension arrays (:issue:`57316`)
27+
- Fixed regression in :meth:`DataFrame.shift` raising ``AssertionError`` for ``axis=1`` and empty :class:`DataFrame` (:issue:`57301`)
2728
- Fixed regression in :meth:`DataFrame.sort_index` not producing a stable sort for a index with duplicates (:issue:`57151`)
2829
- Fixed regression in :meth:`DataFrame.to_dict` with ``orient='list'`` and datetime or timedelta types returning integers (:issue:`54824`)
2930
- 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
@@ -5859,6 +5859,9 @@ def shift(
58595859
)
58605860
fill_value = lib.no_default
58615861

5862+
if self.empty:
5863+
return self.copy()
5864+
58625865
axis = self._get_axis_number(axis)
58635866

58645867
if is_list_like(periods):

pandas/tests/frame/methods/test_shift.py

+6
Original file line numberDiff line numberDiff line change
@@ -756,3 +756,9 @@ def test_shift_with_iterable_check_other_arguments(self):
756756
msg = "Cannot specify `suffix` if `periods` is an int."
757757
with pytest.raises(ValueError, match=msg):
758758
df.shift(1, suffix="fails")
759+
760+
def test_shift_axis_one_empty(self):
761+
# GH#57301
762+
df = DataFrame()
763+
result = df.shift(1, axis=1)
764+
tm.assert_frame_equal(result, df)

0 commit comments

Comments
 (0)