From 7e461a18d9f6928132afec6f48ce968b3e989ba6 Mon Sep 17 00:00:00 2001 From: Kaiqi Dong Date: Mon, 3 Dec 2018 17:43:52 +0100 Subject: [PATCH 1/4] remove \n from docstring --- pandas/core/arrays/datetimes.py | 26 +++++++++++++------------- pandas/core/arrays/timedeltas.py | 16 ++++++++-------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index cfe3afcf3730a..b3df505d56d78 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -82,7 +82,7 @@ def f(self): return result f.__name__ = name - f.__doc__ = docstring + f.__doc__ = "\n{}\n".format(docstring) return property(f) @@ -1072,19 +1072,19 @@ def date(self): return tslib.ints_to_pydatetime(timestamps, box="date") - year = _field_accessor('year', 'Y', "\n The year of the datetime\n") + year = _field_accessor('year', 'Y', "The year of the datetime") month = _field_accessor('month', 'M', - "\n The month as January=1, December=12 \n") - day = _field_accessor('day', 'D', "\nThe days of the datetime\n") - hour = _field_accessor('hour', 'h', "\nThe hours of the datetime\n") - minute = _field_accessor('minute', 'm', "\nThe minutes of the datetime\n") - second = _field_accessor('second', 's', "\nThe seconds of the datetime\n") + "The month as January=1, December=12") + day = _field_accessor('day', 'D', "The days of the datetime") + hour = _field_accessor('hour', 'h', "The hours of the datetime") + minute = _field_accessor('minute', 'm', "The minutes of the datetime") + second = _field_accessor('second', 's', "The seconds of the datetime") microsecond = _field_accessor('microsecond', 'us', - "\nThe microseconds of the datetime\n") + "The microseconds of the datetime") nanosecond = _field_accessor('nanosecond', 'ns', - "\nThe nanoseconds of the datetime\n") + "The nanoseconds of the datetime") weekofyear = _field_accessor('weekofyear', 'woy', - "\nThe week ordinal of the year\n") + "The week ordinal of the year") week = weekofyear _dayofweek_doc = """ The day of the week with Monday=0, Sunday=6. @@ -1129,12 +1129,12 @@ def date(self): "The name of day in a week (ex: Friday)\n\n.. deprecated:: 0.23.0") dayofyear = _field_accessor('dayofyear', 'doy', - "\nThe ordinal day of the year\n") - quarter = _field_accessor('quarter', 'q', "\nThe quarter of the date\n") + "The ordinal day of the year") + quarter = _field_accessor('quarter', 'q', "The quarter of the date") days_in_month = _field_accessor( 'days_in_month', 'dim', - "\nThe number of days in the month\n") + "The number of days in the month") daysinmonth = days_in_month _is_month_doc = """ Indicates whether the date is the {first_or_last} day of the month. diff --git a/pandas/core/arrays/timedeltas.py b/pandas/core/arrays/timedeltas.py index 830283d31a929..4afc9f5483c2a 100644 --- a/pandas/core/arrays/timedeltas.py +++ b/pandas/core/arrays/timedeltas.py @@ -59,7 +59,7 @@ def f(self): return result f.__name__ = name - f.__doc__ = docstring + f.__doc__ = "\n{}\n".format(docstring) return property(f) @@ -684,16 +684,16 @@ def to_pytimedelta(self): return tslibs.ints_to_pytimedelta(self.asi8) days = _field_accessor("days", "days", - "\nNumber of days for each element.\n") + "Number of days for each element.") seconds = _field_accessor("seconds", "seconds", - "\nNumber of seconds (>= 0 and less than 1 day) " - "for each element.\n") + "Number of seconds (>= 0 and less than 1 day) " + "for each element.") microseconds = _field_accessor("microseconds", "microseconds", - "\nNumber of microseconds (>= 0 and less " - "than 1 second) for each element.\n") + "Number of microseconds (>= 0 and less " + "than 1 second) for each element.") nanoseconds = _field_accessor("nanoseconds", "nanoseconds", - "\nNumber of nanoseconds (>= 0 and less " - "than 1 microsecond) for each element.\n") + "Number of nanoseconds (>= 0 and less " + "than 1 microsecond) for each element.") @property def components(self): From ecd9542349c77be5ff800daacdb3679da46855b5 Mon Sep 17 00:00:00 2001 From: Kaiqi Date: Tue, 6 Aug 2019 22:03:39 +0200 Subject: [PATCH 2/4] Add test for issue 13420 --- pandas/tests/groupby/test_categorical.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pandas/tests/groupby/test_categorical.py b/pandas/tests/groupby/test_categorical.py index 486b3b28b29a3..1825d132501a9 100644 --- a/pandas/tests/groupby/test_categorical.py +++ b/pandas/tests/groupby/test_categorical.py @@ -1165,3 +1165,16 @@ def test_seriesgroupby_observed_apply_dict(df_cat, observed, index, data): lambda x: OrderedDict([("min", x.min()), ("max", x.max())]) ) assert_series_equal(result, expected) + + +@pytest.mark.parametrize('code', [ + ([1, 0, 0]), + ([0, 0, 0]) +]) +def test_groupby_categorical_axis_1(code): + # GH 13420 + df = DataFrame({'a': [1, 2, 3, 4], 'b': [-1, -2, -3, -4], 'c': [5, 6, 7, 8]}) + grp = pd.Categorical.from_codes(code, categories=list('abc')) + result = df.groupby(grp, axis=1).mean() + expected = df.T.groupby(grp, axis=0).mean().T + assert_frame_equal(result, expected) From 6ff0dfcc208f0763cf8e4582759bfb1b833df96e Mon Sep 17 00:00:00 2001 From: Kaiqi Date: Tue, 6 Aug 2019 22:31:12 +0200 Subject: [PATCH 3/4] Resolve linting error --- pandas/tests/groupby/test_categorical.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pandas/tests/groupby/test_categorical.py b/pandas/tests/groupby/test_categorical.py index 1825d132501a9..c90406fef052e 100644 --- a/pandas/tests/groupby/test_categorical.py +++ b/pandas/tests/groupby/test_categorical.py @@ -1167,14 +1167,11 @@ def test_seriesgroupby_observed_apply_dict(df_cat, observed, index, data): assert_series_equal(result, expected) -@pytest.mark.parametrize('code', [ - ([1, 0, 0]), - ([0, 0, 0]) -]) +@pytest.mark.parametrize("code", [([1, 0, 0]), ([0, 0, 0])]) def test_groupby_categorical_axis_1(code): # GH 13420 - df = DataFrame({'a': [1, 2, 3, 4], 'b': [-1, -2, -3, -4], 'c': [5, 6, 7, 8]}) - grp = pd.Categorical.from_codes(code, categories=list('abc')) + df = DataFrame({"a": [1, 2, 3, 4], "b": [-1, -2, -3, -4], "c": [5, 6, 7, 8]}) + grp = pd.Categorical.from_codes(code, categories=list("abc")) result = df.groupby(grp, axis=1).mean() expected = df.T.groupby(grp, axis=0).mean().T assert_frame_equal(result, expected) From e63c2d831f31cc741197df5d0d23a23f03d86571 Mon Sep 17 00:00:00 2001 From: Kaiqi Date: Wed, 7 Aug 2019 07:59:32 +0200 Subject: [PATCH 4/4] Change name --- pandas/tests/groupby/test_categorical.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/tests/groupby/test_categorical.py b/pandas/tests/groupby/test_categorical.py index c90406fef052e..eecd5478aaf7b 100644 --- a/pandas/tests/groupby/test_categorical.py +++ b/pandas/tests/groupby/test_categorical.py @@ -1171,7 +1171,7 @@ def test_seriesgroupby_observed_apply_dict(df_cat, observed, index, data): def test_groupby_categorical_axis_1(code): # GH 13420 df = DataFrame({"a": [1, 2, 3, 4], "b": [-1, -2, -3, -4], "c": [5, 6, 7, 8]}) - grp = pd.Categorical.from_codes(code, categories=list("abc")) - result = df.groupby(grp, axis=1).mean() - expected = df.T.groupby(grp, axis=0).mean().T + cat = pd.Categorical.from_codes(code, categories=list("abc")) + result = df.groupby(cat, axis=1).mean() + expected = df.T.groupby(cat, axis=0).mean().T assert_frame_equal(result, expected)