From 7e461a18d9f6928132afec6f48ce968b3e989ba6 Mon Sep 17 00:00:00 2001 From: Kaiqi Dong Date: Mon, 3 Dec 2018 17:43:52 +0100 Subject: [PATCH 01/14] 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 dea38f24c0067ae3fe9484b837c9649714213bba Mon Sep 17 00:00:00 2001 From: Kaiqi Date: Tue, 14 Jan 2020 21:26:31 +0100 Subject: [PATCH 02/14] fix issue 17038 --- pandas/core/reshape/pivot.py | 4 +++- pandas/tests/reshape/test_pivot.py | 20 ++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/pandas/core/reshape/pivot.py b/pandas/core/reshape/pivot.py index b443ba142369c..9743d90f4dd04 100644 --- a/pandas/core/reshape/pivot.py +++ b/pandas/core/reshape/pivot.py @@ -117,7 +117,9 @@ def pivot_table( agged[v] = maybe_downcast_to_dtype(agged[v], data[v].dtype) table = agged - if table.index.nlevels > 1: + + # GH 17038, this check should only happen if index is specified + if table.index.nlevels > 1 and index: # Related GH #17123 # If index_names are integers, determine whether the integers refer # to the level position or name. diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index 743fc50c87e96..46a05123c9fdd 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -896,12 +896,6 @@ def _check_output( totals = table.loc[("All", ""), value_col] assert totals == self.data[value_col].mean() - # no rows - rtable = self.data.pivot_table( - columns=["AA", "BB"], margins=True, aggfunc=np.mean - ) - assert isinstance(rtable, Series) - table = self.data.pivot_table(index=["AA", "BB"], margins=True, aggfunc="mean") for item in ["DD", "EE", "FF"]: totals = table.loc[("All", ""), item] @@ -972,6 +966,20 @@ def test_pivot_integer_columns(self): tm.assert_frame_equal(table, table2, check_names=False) + @pytest.mark.parametrize("cols", [(1, 2), ("a", "b"), (1, "b"), ("a", 1)]) + def test_pivot_table_multiindex_only(self, cols): + # GH 17038 + df2 = DataFrame({cols[0]: [1, 2, 3], cols[1]: [1, 2, 3], "v": [4, 5, 6]}) + + result = df2.pivot_table(values="v", columns=cols) + expected = DataFrame( + [[4, 5, 6]], + columns=MultiIndex.from_tuples([(1, 1), (2, 2), (3, 3)], names=cols), + index=Index(["v"]), + ) + + tm.assert_frame_equal(result, expected) + def test_pivot_no_level_overlap(self): # GH #1181 From cd9e7ac3f31ffaf95cd628863df911dea9fa1248 Mon Sep 17 00:00:00 2001 From: Kaiqi Date: Tue, 14 Jan 2020 21:29:43 +0100 Subject: [PATCH 03/14] revert change --- pandas/core/reshape/pivot.py | 3 +-- pandas/tests/reshape/test_pivot.py | 20 ++++++-------------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/pandas/core/reshape/pivot.py b/pandas/core/reshape/pivot.py index 9743d90f4dd04..a7cdbb0da7a4e 100644 --- a/pandas/core/reshape/pivot.py +++ b/pandas/core/reshape/pivot.py @@ -118,8 +118,7 @@ def pivot_table( table = agged - # GH 17038, this check should only happen if index is specified - if table.index.nlevels > 1 and index: + if table.index.nlevels > 1: # Related GH #17123 # If index_names are integers, determine whether the integers refer # to the level position or name. diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index 46a05123c9fdd..743fc50c87e96 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -896,6 +896,12 @@ def _check_output( totals = table.loc[("All", ""), value_col] assert totals == self.data[value_col].mean() + # no rows + rtable = self.data.pivot_table( + columns=["AA", "BB"], margins=True, aggfunc=np.mean + ) + assert isinstance(rtable, Series) + table = self.data.pivot_table(index=["AA", "BB"], margins=True, aggfunc="mean") for item in ["DD", "EE", "FF"]: totals = table.loc[("All", ""), item] @@ -966,20 +972,6 @@ def test_pivot_integer_columns(self): tm.assert_frame_equal(table, table2, check_names=False) - @pytest.mark.parametrize("cols", [(1, 2), ("a", "b"), (1, "b"), ("a", 1)]) - def test_pivot_table_multiindex_only(self, cols): - # GH 17038 - df2 = DataFrame({cols[0]: [1, 2, 3], cols[1]: [1, 2, 3], "v": [4, 5, 6]}) - - result = df2.pivot_table(values="v", columns=cols) - expected = DataFrame( - [[4, 5, 6]], - columns=MultiIndex.from_tuples([(1, 1), (2, 2), (3, 3)], names=cols), - index=Index(["v"]), - ) - - tm.assert_frame_equal(result, expected) - def test_pivot_no_level_overlap(self): # GH #1181 From e5e912be0f596943067a7df812442764d311a086 Mon Sep 17 00:00:00 2001 From: Kaiqi Date: Tue, 14 Jan 2020 21:30:16 +0100 Subject: [PATCH 04/14] revert change --- pandas/core/reshape/pivot.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/core/reshape/pivot.py b/pandas/core/reshape/pivot.py index a7cdbb0da7a4e..b443ba142369c 100644 --- a/pandas/core/reshape/pivot.py +++ b/pandas/core/reshape/pivot.py @@ -117,7 +117,6 @@ def pivot_table( agged[v] = maybe_downcast_to_dtype(agged[v], data[v].dtype) table = agged - if table.index.nlevels > 1: # Related GH #17123 # If index_names are integers, determine whether the integers refer From 98472baa7aa3b8609dab7c209ad9fd6460c15c46 Mon Sep 17 00:00:00 2001 From: Kaiqi Date: Thu, 16 Jan 2020 22:30:28 +0100 Subject: [PATCH 05/14] fix issue 31016 --- pandas/core/reshape/pivot.py | 36 ++++++-------- pandas/tests/reshape/test_pivot.py | 80 ++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 22 deletions(-) diff --git a/pandas/core/reshape/pivot.py b/pandas/core/reshape/pivot.py index 7109f23761188..f825029f57091 100644 --- a/pandas/core/reshape/pivot.py +++ b/pandas/core/reshape/pivot.py @@ -9,7 +9,7 @@ from pandas.core.dtypes.generic import ABCDataFrame, ABCSeries import pandas.core.common as com -from pandas.core.frame import _shared_docs +from pandas.core.frame import DataFrame, _shared_docs from pandas.core.groupby import Grouper from pandas.core.indexes.api import Index, MultiIndex, get_objs_combined_axis from pandas.core.reshape.concat import concat @@ -226,15 +226,7 @@ def _add_margins( elif values: marginal_result_set = _generate_marginal_results( - table, - data, - values, - rows, - cols, - aggfunc, - observed, - grand_margin, - margins_name, + table, data, values, rows, cols, aggfunc, observed, margins_name, ) if not isinstance(marginal_result_set, tuple): return marginal_result_set @@ -303,15 +295,7 @@ def _compute_grand_margin(data, values, aggfunc, margins_name: str = "All"): def _generate_marginal_results( - table, - data, - values, - rows, - cols, - aggfunc, - observed, - grand_margin, - margins_name: str = "All", + table, data, values, rows, cols, aggfunc, observed, margins_name: str = "All", ): if len(cols) > 0: # need to "interleave" the margins @@ -345,12 +329,20 @@ def _all_key(key): table_pieces.append(piece) margin_keys.append(all_key) else: - margin = grand_margin cat_axis = 0 for key, piece in table.groupby(level=0, axis=cat_axis, observed=observed): - all_key = _all_key(key) + if len(cols) > 1: + all_key = _all_key(key) + else: + all_key = margins_name table_pieces.append(piece) - table_pieces.append(Series(margin[key], index=[all_key])) + # GH31016 this is to calculate margin for each group, and assign + # corresponded key as index + transformed_piece = DataFrame(piece.apply(aggfunc)).T + transformed_piece.index = [all_key] + + # append piece for margin into table_piece + table_pieces.append(transformed_piece) margin_keys.append(all_key) result = concat(table_pieces, axis=cat_axis) diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index e3a57da450334..d315732ca3451 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -901,6 +901,86 @@ def _check_output( totals = table.loc[("All", ""), item] assert totals == self.data[item].mean() + @pytest.mark.parametrize( + "columns, aggfunc, values, expected_columns", + [ + ( + "A", + np.mean, + [[5.5, 5.5, 2.2, 2.2], [8.0, 8.0, 4.4, 4.4]], + Index(["bar", "All", "foo", "All"]), + ), + ( + ["A", "B"], + np.sum, + [[9, 13, 22, 5, 6, 11], [14, 18, 32, 11, 11, 22]], + MultiIndex.from_tuples( + [ + ("bar", "one"), + ("bar", "two"), + ("bar", "All"), + ("foo", "one"), + ("foo", "two"), + ("foo", "All"), + ], + names=["A", "B"], + ), + ), + ( + ["A", "B", "C"], + np.mean, + [ + [4.0, 5.0, 7.0, 6.0, 5.5, 2.0, 1.0, 3.0, 2.0], + [6.0, 8.0, 9.0, 9.0, 8.0, 4.5, 2.0, 5.5, 4.0], + ], + MultiIndex.from_tuples( + [ + ("bar", "one", "large"), + ("bar", "one", "small"), + ("bar", "two", "large"), + ("bar", "two", "small"), + ("bar", "All", ""), + ("foo", "one", "large"), + ("foo", "one", "small"), + ("foo", "two", "small"), + ("foo", "All", ""), + ], + names=["A", "B", "C"], + ), + ), + ], + ) + def test_margin_with_only_columns_defined( + self, columns, aggfunc, values, expected_columns + ): + # GH 31016 + df = pd.DataFrame( + { + "A": ["foo", "foo", "foo", "foo", "foo", "bar", "bar", "bar", "bar"], + "B": ["one", "one", "one", "two", "two", "one", "one", "two", "two"], + "C": [ + "small", + "large", + "large", + "small", + "small", + "large", + "small", + "small", + "large", + ], + "D": [1, 2, 2, 3, 3, 4, 5, 6, 7], + "E": [2, 4, 5, 5, 6, 6, 8, 9, 9], + } + ) + + result = df.pivot_table(columns=columns, margins=True, aggfunc=aggfunc) + expected = pd.DataFrame( + values, index=Index(["D", "E"]), columns=expected_columns + ) + + tm.assert_frame_equal(result, expected) + def test_margins_dtype(self): # GH 17013 From e13c45b2bcd51be8a8fa7b2032d9fe527404a4f6 Mon Sep 17 00:00:00 2001 From: Kaiqi Date: Thu, 16 Jan 2020 22:35:29 +0100 Subject: [PATCH 06/14] add whatsnew --- doc/source/whatsnew/v1.1.0.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index b5a7b19f160a4..027ec3fd895db 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -142,6 +142,8 @@ Reshaping - - Bug in :meth:`DataFrame.pivot_table` when only MultiIndexed columns is set (:issue:`17038`) +- Bug in :meth:`DataFrame.pivot_table` when ``margin`` is ``True`` and only ``column`` is defined (:issue:`31016`) + Sparse ^^^^^^ From 8fbee87c14b33112553a23e8acb070915e91d574 Mon Sep 17 00:00:00 2001 From: Kaiqi Date: Thu, 16 Jan 2020 22:49:05 +0100 Subject: [PATCH 07/14] remove redundent test --- pandas/tests/reshape/test_pivot.py | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index d315732ca3451..f00586128f7ad 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -926,28 +926,6 @@ def _check_output( names=["A", "B"], ), ), - ( - ["A", "B", "C"], - np.mean, - [ - [4.0, 5.0, 7.0, 6.0, 5.5, 2.0, 1.0, 3.0, 2.0], - [6.0, 8.0, 9.0, 9.0, 8.0, 4.5, 2.0, 5.5, 4.0], - ], - MultiIndex.from_tuples( - [ - ("bar", "one", "large"), - ("bar", "one", "small"), - ("bar", "two", "large"), - ("bar", "two", "small"), - ("bar", "All", ""), - ("foo", "one", "large"), - ("foo", "one", "small"), - ("foo", "two", "small"), - ("foo", "All", ""), - ], - names=["A", "B", "C"], - ), - ), ], ) def test_margin_with_only_columns_defined( From fea8db881290c6befa53ce91444949dd3251c916 Mon Sep 17 00:00:00 2001 From: Kaiqi Date: Thu, 16 Jan 2020 23:10:34 +0100 Subject: [PATCH 08/14] fix linting --- pandas/core/reshape/pivot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/reshape/pivot.py b/pandas/core/reshape/pivot.py index f825029f57091..e2377abcc9882 100644 --- a/pandas/core/reshape/pivot.py +++ b/pandas/core/reshape/pivot.py @@ -9,7 +9,7 @@ from pandas.core.dtypes.generic import ABCDataFrame, ABCSeries import pandas.core.common as com -from pandas.core.frame import DataFrame, _shared_docs +from pandas.core.frame import _shared_docs from pandas.core.groupby import Grouper from pandas.core.indexes.api import Index, MultiIndex, get_objs_combined_axis from pandas.core.reshape.concat import concat From 258aacd20b098a4d15cbe3d5035e59929a1a6039 Mon Sep 17 00:00:00 2001 From: Kaiqi Date: Thu, 16 Jan 2020 23:27:39 +0100 Subject: [PATCH 09/14] fix import --- pandas/core/reshape/pivot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/reshape/pivot.py b/pandas/core/reshape/pivot.py index e2377abcc9882..f825029f57091 100644 --- a/pandas/core/reshape/pivot.py +++ b/pandas/core/reshape/pivot.py @@ -9,7 +9,7 @@ from pandas.core.dtypes.generic import ABCDataFrame, ABCSeries import pandas.core.common as com -from pandas.core.frame import _shared_docs +from pandas.core.frame import DataFrame, _shared_docs from pandas.core.groupby import Grouper from pandas.core.indexes.api import Index, MultiIndex, get_objs_combined_axis from pandas.core.reshape.concat import concat From 2fc662269c312e3b7af76430745b2ade52ff1dd6 Mon Sep 17 00:00:00 2001 From: Kaiqi Date: Fri, 17 Jan 2020 08:51:15 +0100 Subject: [PATCH 10/14] fix import issue --- pandas/core/reshape/pivot.py | 4 +++- pandas/tests/reshape/test_pivot.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/core/reshape/pivot.py b/pandas/core/reshape/pivot.py index f825029f57091..0bb048185fb65 100644 --- a/pandas/core/reshape/pivot.py +++ b/pandas/core/reshape/pivot.py @@ -9,7 +9,7 @@ from pandas.core.dtypes.generic import ABCDataFrame, ABCSeries import pandas.core.common as com -from pandas.core.frame import DataFrame, _shared_docs +from pandas.core.frame import _shared_docs from pandas.core.groupby import Grouper from pandas.core.indexes.api import Index, MultiIndex, get_objs_combined_axis from pandas.core.reshape.concat import concat @@ -329,6 +329,8 @@ def _all_key(key): table_pieces.append(piece) margin_keys.append(all_key) else: + from pandas import DataFrame + cat_axis = 0 for key, piece in table.groupby(level=0, axis=cat_axis, observed=observed): if len(cols) > 1: diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index f00586128f7ad..e4b3d61f2e159 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -912,7 +912,7 @@ def _check_output( ), ( ["A", "B"], - np.sum, + "sum", [[9, 13, 22, 5, 6, 11], [14, 18, 32, 11, 11, 22]], MultiIndex.from_tuples( [ From 436b7a20fd64bd51d2c79a68966169d2681d9fc1 Mon Sep 17 00:00:00 2001 From: Kaiqi Date: Fri, 17 Jan 2020 20:04:11 +0100 Subject: [PATCH 11/14] more robust --- pandas/core/reshape/pivot.py | 2 +- pandas/tests/reshape/test_pivot.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/reshape/pivot.py b/pandas/core/reshape/pivot.py index 0bb048185fb65..1eb27aea7ff32 100644 --- a/pandas/core/reshape/pivot.py +++ b/pandas/core/reshape/pivot.py @@ -341,7 +341,7 @@ def _all_key(key): # GH31016 this is to calculate margin for each group, and assign # corresponded key as index transformed_piece = DataFrame(piece.apply(aggfunc)).T - transformed_piece.index = [all_key] + transformed_piece.index = Index([all_key], name=piece.index.name) # append piece for margin into table_piece table_pieces.append(transformed_piece) diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index e4b3d61f2e159..1510f144dc065 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -908,7 +908,7 @@ def _check_output( "A", np.mean, [[5.5, 5.5, 2.2, 2.2], [8.0, 8.0, 4.4, 4.4]], - Index(["bar", "All", "foo", "All"]), + Index(["bar", "All", "foo", "All"], name="A"), ), ( ["A", "B"], From d1f184d3062848aa3476ce53000be2f7592c3a70 Mon Sep 17 00:00:00 2001 From: Kaiqi Date: Sat, 18 Jan 2020 19:17:09 +0100 Subject: [PATCH 12/14] add asv --- asv_bench/benchmarks/reshape.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/asv_bench/benchmarks/reshape.py b/asv_bench/benchmarks/reshape.py index 441f4b380656e..0581a991342cd 100644 --- a/asv_bench/benchmarks/reshape.py +++ b/asv_bench/benchmarks/reshape.py @@ -160,6 +160,9 @@ def time_pivot_table_categorical_observed(self): fill_value=0, observed=True, ) + + def time_pivot_table_margins_only_column(self): + self.df.pivot_table(columns=["key2", "key3"], margins=True, aggfunc=np.sum) class Crosstab: From fe9e8bc563a2560f3495be720a8f28f8fcece40d Mon Sep 17 00:00:00 2001 From: Kaiqi Date: Sat, 18 Jan 2020 19:18:52 +0100 Subject: [PATCH 13/14] fix pep8 --- asv_bench/benchmarks/reshape.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asv_bench/benchmarks/reshape.py b/asv_bench/benchmarks/reshape.py index 0581a991342cd..c91b40068e753 100644 --- a/asv_bench/benchmarks/reshape.py +++ b/asv_bench/benchmarks/reshape.py @@ -160,7 +160,7 @@ def time_pivot_table_categorical_observed(self): fill_value=0, observed=True, ) - + def time_pivot_table_margins_only_column(self): self.df.pivot_table(columns=["key2", "key3"], margins=True, aggfunc=np.sum) From c01d714242c91a075c013c8666520d4a95b95300 Mon Sep 17 00:00:00 2001 From: Kaiqi Date: Sat, 18 Jan 2020 19:20:47 +0100 Subject: [PATCH 14/14] fix pep8 --- asv_bench/benchmarks/reshape.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asv_bench/benchmarks/reshape.py b/asv_bench/benchmarks/reshape.py index c91b40068e753..21081ee23a773 100644 --- a/asv_bench/benchmarks/reshape.py +++ b/asv_bench/benchmarks/reshape.py @@ -162,7 +162,7 @@ def time_pivot_table_categorical_observed(self): ) def time_pivot_table_margins_only_column(self): - self.df.pivot_table(columns=["key2", "key3"], margins=True, aggfunc=np.sum) + self.df.pivot_table(columns=["key2", "key3"], margins=True) class Crosstab: