From 14827d382cb56f4b3925374936e2a250bc8cff68 Mon Sep 17 00:00:00 2001 From: Alexey Prutskov Date: Fri, 28 Aug 2020 16:40:50 +0300 Subject: [PATCH] FIX-#1646: Fix representation of `Series` with datetimelike index (#1954) Signed-off-by: Alexey Prutskov --- modin/pandas/series.py | 11 ++++++++--- modin/pandas/test/test_series.py | 26 ++++++++++++++++++-------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/modin/pandas/series.py b/modin/pandas/series.py index 939806c3bda..ce8c1459d88 100644 --- a/modin/pandas/series.py +++ b/modin/pandas/series.py @@ -308,6 +308,11 @@ def __repr__(self): if isinstance(temp_df, pandas.DataFrame) and not temp_df.empty: temp_df = temp_df.iloc[:, 0] temp_str = repr(temp_df) + freq_str = ( + "Freq: {}, ".format(self.index.freqstr) + if isinstance(self.index, pandas.DatetimeIndex) + else "" + ) if self.name is not None: name_str = "Name: {}, ".format(str(self.name)) else: @@ -322,9 +327,9 @@ def __repr__(self): else temp_str.rsplit("dtype: ", 1)[-1] ) if len(self) == 0: - return "Series([], {}{}".format(name_str, dtype_str) - return temp_str.rsplit("\nName:", 1)[0] + "\n{}{}{}".format( - name_str, len_str, dtype_str + return "Series([], {}{}{}".format(freq_str, name_str, dtype_str) + return temp_str.rsplit("\n", 1)[0] + "\n{}{}{}{}".format( + freq_str, name_str, len_str, dtype_str ) def __round__(self, decimals=0): diff --git a/modin/pandas/test/test_series.py b/modin/pandas/test/test_series.py index b866e585ef3..57dc0c8a3de 100644 --- a/modin/pandas/test/test_series.py +++ b/modin/pandas/test/test_series.py @@ -474,14 +474,24 @@ def test___pow__(data): inter_df_math_helper(modin_series, pandas_series, "__pow__") -def test___repr___empty(): - modin_series, pandas_series = pd.Series(), pandas.Series() - assert repr(modin_series) == repr(pandas_series) - - -@pytest.mark.parametrize("data", test_data_values, ids=test_data_keys) -def test___repr__(data): - modin_series, pandas_series = create_test_series(data) +@pytest.mark.parametrize("name", ["Dates", None]) +@pytest.mark.parametrize( + "dt_index", [True, False], ids=["dt_index_true", "dt_index_false"] +) +@pytest.mark.parametrize( + "data", [*test_data_values, "empty"], ids=[*test_data_keys, "empty"] +) +def test___repr__(name, dt_index, data): + if data == "empty": + modin_series, pandas_series = pd.Series(), pandas.Series() + else: + modin_series, pandas_series = create_test_series(data) + pandas_series.name = modin_series.name = name + if dt_index: + index = pandas.date_range( + "1/1/2000", periods=len(pandas_series.index), freq="T" + ) + pandas_series.index = modin_series.index = index assert repr(modin_series) == repr(pandas_series)