Skip to content

Commit

Permalink
Add implementation for tshift (#1016)
Browse files Browse the repository at this point in the history
* Add implementation for `tshift`

* Resolves #1015
* Add implementation for `tshift`
* Update and improve tests

* Update Documentation
  • Loading branch information
devin-petersohn authored Jan 19, 2020
1 parent 8a1dea1 commit 32490fb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/UsingPandasonRay/dataframe_supported.rst
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ default to pandas.
+---------------------------+---------------------------------+----------------------------------------------------+
| `truncate`_ | D | |
+---------------------------+---------------------------------+----------------------------------------------------+
| `tshift`_ | D | |
| `tshift`_ | Y | |
+---------------------------+---------------------------------+----------------------------------------------------+
| `tz_convert`_ | Y | |
+---------------------------+---------------------------------+----------------------------------------------------+
Expand Down
4 changes: 3 additions & 1 deletion modin/pandas/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3148,7 +3148,9 @@ def truncate(self, before=None, after=None, axis=None, copy=True):
)

def tshift(self, periods=1, freq=None, axis=0):
return self._default_to_pandas("tshift", periods=periods, freq=freq, axis=axis)
axis = self._get_axis_number(axis)
new_labels = self.axes[axis].shift(periods, freq=freq)
return self.set_axis(new_labels, axis=axis, inplace=False)

def transform(self, func, axis=0, *args, **kwargs):
kwargs["is_transform"] = True
Expand Down
8 changes: 4 additions & 4 deletions modin/pandas/test/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2619,10 +2619,10 @@ def test_truncate(self):

def test_tshift(self):
idx = pd.date_range("1/1/2012", periods=5, freq="M")
df = pd.DataFrame(np.random.randint(0, 100, size=(len(idx), 4)), index=idx)

with pytest.warns(UserWarning):
df.to_period().tshift()
data = np.random.randint(0, 100, size=(len(idx), 4))
modin_df = pd.DataFrame(data, index=idx)
pandas_df = pandas.DataFrame(data, index=idx)
df_equals(modin_df.tshift(4), pandas_df.tshift(4))

def test_tz_convert(self):
modin_idx = pd.date_range(
Expand Down
7 changes: 4 additions & 3 deletions modin/pandas/test/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2600,9 +2600,10 @@ def test_truncate(data):

def test_tshift():
idx = pd.date_range("1/1/2012", periods=5, freq="M")
modin_series = pd.Series(np.random.randint(0, 100, size=len(idx)), index=idx)
with pytest.warns(UserWarning):
modin_series.to_period().tshift()
data = np.random.randint(0, 100, size=len(idx))
modin_series = pd.Series(data, index=idx)
pandas_series = pandas.Series(data, index=idx)
df_equals(modin_series.tshift(4), pandas_series.tshift(4))


def test_tz_convert():
Expand Down

0 comments on commit 32490fb

Please sign in to comment.