Skip to content

Commit

Permalink
Backport PR pandas-dev#57340: REGR: shift raising for axis=1 and empt…
Browse files Browse the repository at this point in the history
…y df
  • Loading branch information
phofl authored and meeseeksmachine committed Feb 12, 2024
1 parent 947f5ae commit b6099b9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.2.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Fixed regressions
- Fixed regression in :meth:`DataFrame.groupby` raising ``ValueError`` when grouping by a :class:`Series` in some cases (:issue:`57276`)
- Fixed regression in :meth:`DataFrame.loc` raising ``IndexError`` for non-unique, masked dtype indexes where result has more than 10,000 rows (:issue:`57027`)
- Fixed regression in :meth:`DataFrame.merge` raising ``ValueError`` for certain types of 3rd-party extension arrays (:issue:`57316`)
- Fixed regression in :meth:`DataFrame.shift` raising ``AssertionError`` for ``axis=1`` and empty :class:`DataFrame` (:issue:`57301`)
- Fixed regression in :meth:`DataFrame.sort_index` not producing a stable sort for a index with duplicates (:issue:`57151`)
- Fixed regression in :meth:`DataFrame.to_dict` with ``orient='list'`` and datetime or timedelta types returning integers (:issue:`54824`)
- Fixed regression in :meth:`DataFrame.to_json` converting nullable integers to floats (:issue:`57224`)
Expand Down
3 changes: 3 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -5859,6 +5859,9 @@ def shift(
)
fill_value = lib.no_default

if self.empty:
return self.copy()

axis = self._get_axis_number(axis)

if is_list_like(periods):
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/frame/methods/test_shift.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,3 +756,9 @@ def test_shift_with_iterable_check_other_arguments(self):
msg = "Cannot specify `suffix` if `periods` is an int."
with pytest.raises(ValueError, match=msg):
df.shift(1, suffix="fails")

def test_shift_axis_one_empty(self):
# GH#57301
df = DataFrame()
result = df.shift(1, axis=1)
tm.assert_frame_equal(result, df)

0 comments on commit b6099b9

Please sign in to comment.