From 010ed74e2dbec123e790514fcf4825a7b66dfe25 Mon Sep 17 00:00:00 2001 From: lfffkh <1906921213@qq.com> Date: Tue, 29 Oct 2024 17:51:52 +0800 Subject: [PATCH 1/2] new-commit --- pandas/core/frame.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 24a164aa15427..005445e30a4fc 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -5706,7 +5706,12 @@ def shift( ) if self.empty: - return self.copy() + self["__temp_column__"] = None + shifted_self = super().shift( + periods=periods, freq=freq, axis=axis, fill_value=fill_value + ) + shifted_self.drop("__temp_column__", axis=1, inplace=True) + return shifted_self axis = self._get_axis_number(axis) From 9ecaf664723196045ebbe81f9d509ace3a5ee18f Mon Sep 17 00:00:00 2001 From: lfffkh <1906921213@qq.com> Date: Tue, 29 Oct 2024 19:51:05 +0800 Subject: [PATCH 2/2] commit2 --- pandas/core/frame.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 005445e30a4fc..a83aa5bbe821b 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -5706,12 +5706,10 @@ def shift( ) if self.empty: - self["__temp_column__"] = None - shifted_self = super().shift( - periods=periods, freq=freq, axis=axis, fill_value=fill_value - ) - shifted_self.drop("__temp_column__", axis=1, inplace=True) - return shifted_self + if axis == 1: + return DataFrame(index=self.index, columns=self.columns.shift(periods)) + else: + return DataFrame(index=self.index.shift(periods), columns=self.columns) axis = self._get_axis_number(axis)