Skip to content

Commit

Permalink
FIX-modin-project#1646: Fix representation of Series with datetimel…
Browse files Browse the repository at this point in the history
…ike index (modin-project#1954)

Signed-off-by: Alexey Prutskov <alexey.prutskov@intel.com>
  • Loading branch information
prutskov authored and aregm committed Sep 16, 2020
1 parent 605deb4 commit 8133153
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
11 changes: 8 additions & 3 deletions modin/pandas/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
Expand Down
26 changes: 18 additions & 8 deletions modin/pandas/test/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 8133153

Please sign in to comment.