Skip to content

Commit

Permalink
BUG: Frequency shift on empty DataFrame (#60172)
Browse files Browse the repository at this point in the history
* freq shift

* Save local changes before merging
  • Loading branch information
eightyseven authored Nov 5, 2024
1 parent 34387bd commit b84e0c8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,7 @@ Other
- Bug in :meth:`DataFrame.eval` and :meth:`DataFrame.query` which caused an exception when using NumPy attributes via ``@`` notation, e.g., ``df.eval("@np.floor(a)")``. (:issue:`58041`)
- Bug in :meth:`DataFrame.eval` and :meth:`DataFrame.query` which did not allow to use ``tan`` function. (:issue:`55091`)
- Bug in :meth:`DataFrame.query` which raised an exception or produced incorrect results when expressions contained backtick-quoted column names containing the hash character ``#``, backticks, or characters that fall outside the ASCII range (U+0001..U+007F). (:issue:`59285`) (:issue:`49633`)
- Bug in :meth:`DataFrame.shift` where passing a ``freq`` on a DataFrame with no columns did not shift the index correctly. (:issue:`60102`)
- Bug in :meth:`DataFrame.sort_index` when passing ``axis="columns"`` and ``ignore_index=True`` and ``ascending=False`` not returning a :class:`RangeIndex` columns (:issue:`57293`)
- Bug in :meth:`DataFrame.transform` that was returning the wrong order unless the index was monotonically increasing. (:issue:`57069`)
- Bug in :meth:`DataFrame.where` where using a non-bool type array in the function would return a ``ValueError`` instead of a ``TypeError`` (:issue:`56330`)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -5705,7 +5705,7 @@ def shift(
"Passing a 'freq' together with a 'fill_value' is not allowed."
)

if self.empty:
if self.empty and freq is None:
return self.copy()

axis = self._get_axis_number(axis)
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/frame/methods/test_shift.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,3 +747,13 @@ def test_shift_axis_one_empty(self):
df = DataFrame()
result = df.shift(1, axis=1)
tm.assert_frame_equal(result, df)

def test_shift_with_offsets_freq_empty(self):
# GH#60102
dates = date_range("2020-01-01", periods=3, freq="D")
offset = offsets.Day()
shifted_dates = dates + offset
df = DataFrame(index=dates)
df_shifted = DataFrame(index=shifted_dates)
result = df.shift(freq=offset)
tm.assert_frame_equal(result, df_shifted)

0 comments on commit b84e0c8

Please sign in to comment.