Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement tz_localize for Series and DataFrame #1014

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/UsingPandasonRay/dataframe_supported.rst
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ default to pandas.
+---------------------------+---------------------------------+----------------------------------------------------+
| `tz_convert`_ | D | |
+---------------------------+---------------------------------+----------------------------------------------------+
| `tz_localize`_ | D | |
| `tz_localize`_ | Y | |
+---------------------------+---------------------------------+----------------------------------------------------+
| `unstack`_ | D | |
+---------------------------+---------------------------------+----------------------------------------------------+
Expand Down
21 changes: 13 additions & 8 deletions modin/pandas/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3161,15 +3161,20 @@ def tz_convert(self, tz, axis=0, level=None, copy=True):
def tz_localize(
self, tz, axis=0, level=None, copy=True, ambiguous="raise", nonexistent="raise"
):
return self._default_to_pandas(
"tz_localize",
tz,
axis=axis,
level=level,
copy=copy,
ambiguous=ambiguous,
nonexistent=nonexistent,
axis = self._get_axis_number(axis)
new_labels = (
pandas.Series(index=self.axes[axis])
.tz_localize(
tz,
axis=axis,
level=level,
copy=False,
ambiguous=ambiguous,
nonexistent=nonexistent,
)
.index
)
return self.set_axis(labels=new_labels, axis=axis, inplace=not copy)

def unstack(self, level=-1, fill_value=None):
return self._default_to_pandas("unstack", level=level, fill_value=fill_value)
Expand Down
16 changes: 11 additions & 5 deletions modin/pandas/test/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2622,11 +2622,17 @@ def test_tz_convert(self):
df.tz_localize("America/Los_Angeles").tz_convert("America/Los_Angeles")

def test_tz_localize(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.tz_localize("America/Los_Angeles")
idx = pd.date_range("1/1/2012", periods=400, freq="2D")
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.tz_localize("UTC", axis=0), pandas_df.tz_localize("UTC", axis=0)
)
df_equals(
modin_df.tz_localize("America/Los_Angeles", axis=0),
pandas_df.tz_localize("America/Los_Angeles", axis=0),
)

def test_unstack(self):
data = test_data_values[0]
Expand Down
15 changes: 11 additions & 4 deletions modin/pandas/test/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2607,10 +2607,17 @@ def test_tz_convert():


def test_tz_localize():
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.tz_localize("America/Los_Angeles")
idx = pd.date_range("1/1/2012", periods=400, freq="2D")
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.tz_localize("America/Los_Angeles"),
pandas_series.tz_localize("America/Los_Angeles"),
)
df_equals(
modin_series.tz_localize("UTC"), pandas_series.tz_localize("UTC"),
)


@pytest.mark.parametrize("data", test_data_values, ids=test_data_keys)
Expand Down