From 6140d5a894a5c86d850dd4294d54bf9a911e8548 Mon Sep 17 00:00:00 2001 From: blueTaxi <32769797+blueTaxi@users.noreply.github.com> Date: Sun, 21 Jan 2018 08:58:27 +1100 Subject: [PATCH 01/14] Add test --- pandas/tests/reshape/test_pivot.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index 786c57a4a82df..66b24a8bad279 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -1628,7 +1628,8 @@ def test_crosstab_dup_index_names(self): pytest.raises(ValueError, pd.crosstab, s, s) @pytest.mark.parametrize("names", [['a', ('b', 'c')], - [('a', 'b'), 'c']]) + [('a', 'b'), 'c'], + [('a', 'b'), ('c', 'd')]]) def test_crosstab_tuple_name(self, names): s1 = pd.Series(range(3), name=names[0]) s2 = pd.Series(range(1, 4), name=names[1]) @@ -1638,3 +1639,6 @@ def test_crosstab_tuple_name(self, names): result = pd.crosstab(s1, s2) tm.assert_frame_equal(result, expected) + + result_col_list = list(result.columns) + assert result_col_list == [1, 2, 3] From 6bcb2d704c9094f08403796ca70c8579ffb882e2 Mon Sep 17 00:00:00 2001 From: blueTaxi <32769797+blueTaxi@users.noreply.github.com> Date: Sun, 21 Jan 2018 08:59:07 +1100 Subject: [PATCH 02/14] Add logic to fix CI failure from new test --- pandas/core/reshape/pivot.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pandas/core/reshape/pivot.py b/pandas/core/reshape/pivot.py index 0e92fc4edce85..e89ba977b195b 100644 --- a/pandas/core/reshape/pivot.py +++ b/pandas/core/reshape/pivot.py @@ -455,17 +455,22 @@ def crosstab(index, columns, values=None, rownames=None, colnames=None, from pandas import DataFrame df = DataFrame(data, index=common_idx) + original_columns_set = set(df.columns.values) if values is None: df['__dummy__'] = 0 kwargs = {'aggfunc': len, 'fill_value': 0} else: df['__dummy__'] = values kwargs = {'aggfunc': aggfunc} + added_column = list(set(df.columns.values) - original_columns_set)[0] table = df.pivot_table('__dummy__', index=rownames, columns=colnames, margins=margins, margins_name=margins_name, dropna=dropna, **kwargs) + if not table.empty: + table = table[added_column] + # Post-process if normalize is not False: table = _normalize(table, normalize=normalize, margins=margins, From c1e87e6e28b03ba4d6598526f559a9bfb226ecba Mon Sep 17 00:00:00 2001 From: blueTaxi <32769797+blueTaxi@users.noreply.github.com> Date: Sun, 21 Jan 2018 09:27:24 +1100 Subject: [PATCH 03/14] fix CI failure --- 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 e89ba977b195b..4725f23249da8 100644 --- a/pandas/core/reshape/pivot.py +++ b/pandas/core/reshape/pivot.py @@ -464,7 +464,7 @@ def crosstab(index, columns, values=None, rownames=None, colnames=None, kwargs = {'aggfunc': aggfunc} added_column = list(set(df.columns.values) - original_columns_set)[0] - table = df.pivot_table('__dummy__', index=rownames, columns=colnames, + table = df.pivot_table(['__dummy__'], index=rownames, columns=colnames, margins=margins, margins_name=margins_name, dropna=dropna, **kwargs) From af90130287cf5190bebb7ef0cbdd6d1ba77aa0c6 Mon Sep 17 00:00:00 2001 From: blueTaxi <32769797+blueTaxi@users.noreply.github.com> Date: Sun, 21 Jan 2018 10:10:25 +1100 Subject: [PATCH 04/14] Added documentation for the bug fix --- doc/source/whatsnew/v0.23.0.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v0.23.0.txt b/doc/source/whatsnew/v0.23.0.txt index 86fc47dee09fc..ab3366354d68c 100644 --- a/doc/source/whatsnew/v0.23.0.txt +++ b/doc/source/whatsnew/v0.23.0.txt @@ -509,6 +509,7 @@ Reshaping - Bug in :func:`DataFrame.merge` in which merging using ``Index`` objects as vectors raised an Exception (:issue:`19038`) - Bug in :func:`DataFrame.stack`, :func:`DataFrame.unstack`, :func:`Series.unstack` which were not returning subclasses (:issue:`15563`) - Bug in timezone comparisons, manifesting as a conversion of the index to UTC in ``.concat()`` (:issue:`18523`) +- Bug in :func:`crosstab` where the added column is removed incorrectly (:issue:`18321`) - Numeric From 8f4380fb25ce22d0ae48258cdadd182dd2e22aec Mon Sep 17 00:00:00 2001 From: Tuan Date: Mon, 22 Jan 2018 21:01:54 +1100 Subject: [PATCH 05/14] added more test and fixed up code based on comments of first pull request --- pandas/core/reshape/pivot.py | 7 ++++--- pandas/tests/reshape/test_pivot.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/pandas/core/reshape/pivot.py b/pandas/core/reshape/pivot.py index 4725f23249da8..aaa908721f4c4 100644 --- a/pandas/core/reshape/pivot.py +++ b/pandas/core/reshape/pivot.py @@ -455,21 +455,22 @@ def crosstab(index, columns, values=None, rownames=None, colnames=None, from pandas import DataFrame df = DataFrame(data, index=common_idx) - original_columns_set = set(df.columns.values) + common_cols_idx = df.columns + if values is None: df['__dummy__'] = 0 kwargs = {'aggfunc': len, 'fill_value': 0} else: df['__dummy__'] = values kwargs = {'aggfunc': aggfunc} - added_column = list(set(df.columns.values) - original_columns_set)[0] table = df.pivot_table(['__dummy__'], index=rownames, columns=colnames, margins=margins, margins_name=margins_name, dropna=dropna, **kwargs) if not table.empty: - table = table[added_column] + added_cols_idx= df.columns.difference(common_cols_idx).values[0] + table = table[added_cols_idx] # Post-process if normalize is not False: diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index 66b24a8bad279..6d001e3deb83d 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -1640,5 +1640,19 @@ def test_crosstab_tuple_name(self, names): result = pd.crosstab(s1, s2) tm.assert_frame_equal(result, expected) + @pytest.mark.parametrize("names", [['a', 'b'], + [('a', 'b'), 'c'], + [('a', 'b'), ('c', 'd')], + [(1, 2, 3), ('a', 'b', 'c')]]) + def test_crosstab_cols_output(self, names): + s1 = pd.Series(range(3), name=names[0]) + s2 = pd.Series(range(1, 4), name=names[1]) + result = pd.crosstab(s1, s2) result_col_list = list(result.columns) assert result_col_list == [1, 2, 3] + + s1 = pd.Series(range(0), name=names[0]) + s2 = pd.Series(range(1, 4), name=names[1]) + result = pd.crosstab(s1, s2) + result_col_list = list(result.columns) + assert result_col_list == [] From 451792fcfcbfeca8e55328eaacc85b20254b1be7 Mon Sep 17 00:00:00 2001 From: blueTaxi <32769797+blueTaxi@users.noreply.github.com> Date: Mon, 22 Jan 2018 21:13:59 +1100 Subject: [PATCH 06/14] Update tests --- pandas/tests/reshape/test_pivot.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index 66b24a8bad279..6d001e3deb83d 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -1640,5 +1640,19 @@ def test_crosstab_tuple_name(self, names): result = pd.crosstab(s1, s2) tm.assert_frame_equal(result, expected) + @pytest.mark.parametrize("names", [['a', 'b'], + [('a', 'b'), 'c'], + [('a', 'b'), ('c', 'd')], + [(1, 2, 3), ('a', 'b', 'c')]]) + def test_crosstab_cols_output(self, names): + s1 = pd.Series(range(3), name=names[0]) + s2 = pd.Series(range(1, 4), name=names[1]) + result = pd.crosstab(s1, s2) result_col_list = list(result.columns) assert result_col_list == [1, 2, 3] + + s1 = pd.Series(range(0), name=names[0]) + s2 = pd.Series(range(1, 4), name=names[1]) + result = pd.crosstab(s1, s2) + result_col_list = list(result.columns) + assert result_col_list == [] From 30da7f4dc123ce620ae0f63c0f12693e6005696a Mon Sep 17 00:00:00 2001 From: blueTaxi <32769797+blueTaxi@users.noreply.github.com> Date: Mon, 22 Jan 2018 21:14:36 +1100 Subject: [PATCH 07/14] Update logic --- pandas/core/reshape/pivot.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pandas/core/reshape/pivot.py b/pandas/core/reshape/pivot.py index 4725f23249da8..aaa908721f4c4 100644 --- a/pandas/core/reshape/pivot.py +++ b/pandas/core/reshape/pivot.py @@ -455,21 +455,22 @@ def crosstab(index, columns, values=None, rownames=None, colnames=None, from pandas import DataFrame df = DataFrame(data, index=common_idx) - original_columns_set = set(df.columns.values) + common_cols_idx = df.columns + if values is None: df['__dummy__'] = 0 kwargs = {'aggfunc': len, 'fill_value': 0} else: df['__dummy__'] = values kwargs = {'aggfunc': aggfunc} - added_column = list(set(df.columns.values) - original_columns_set)[0] table = df.pivot_table(['__dummy__'], index=rownames, columns=colnames, margins=margins, margins_name=margins_name, dropna=dropna, **kwargs) if not table.empty: - table = table[added_column] + added_cols_idx= df.columns.difference(common_cols_idx).values[0] + table = table[added_cols_idx] # Post-process if normalize is not False: From 0970999e134944e4087e94cfabbf55b967c2ca80 Mon Sep 17 00:00:00 2001 From: blueTaxi <32769797+blueTaxi@users.noreply.github.com> Date: Mon, 22 Jan 2018 21:17:49 +1100 Subject: [PATCH 08/14] fix pep8 --- 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 aaa908721f4c4..cd755d656a710 100644 --- a/pandas/core/reshape/pivot.py +++ b/pandas/core/reshape/pivot.py @@ -469,7 +469,7 @@ def crosstab(index, columns, values=None, rownames=None, colnames=None, dropna=dropna, **kwargs) if not table.empty: - added_cols_idx= df.columns.difference(common_cols_idx).values[0] + added_cols_idx = df.columns.difference(common_cols_idx).values[0] table = table[added_cols_idx] # Post-process From 52072aeae5fe88a5f8a1b7231a2439b126cbae47 Mon Sep 17 00:00:00 2001 From: Tuan Date: Tue, 23 Jan 2018 21:17:43 +1100 Subject: [PATCH 09/14] pull request 3 --- pandas/core/reshape/pivot.py | 2 +- pandas/tests/reshape/test_pivot.py | 31 ++++++++++++++++++++---------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/pandas/core/reshape/pivot.py b/pandas/core/reshape/pivot.py index aaa908721f4c4..37fab82d7b5f1 100644 --- a/pandas/core/reshape/pivot.py +++ b/pandas/core/reshape/pivot.py @@ -469,7 +469,7 @@ def crosstab(index, columns, values=None, rownames=None, colnames=None, dropna=dropna, **kwargs) if not table.empty: - added_cols_idx= df.columns.difference(common_cols_idx).values[0] + added_cols_idx= list(df.columns.difference(common_cols_idx))[0] table = table[added_cols_idx] # Post-process diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index 6d001e3deb83d..4b8b564ea1abe 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -1645,14 +1645,25 @@ def test_crosstab_tuple_name(self, names): [('a', 'b'), ('c', 'd')], [(1, 2, 3), ('a', 'b', 'c')]]) def test_crosstab_cols_output(self, names): - s1 = pd.Series(range(3), name=names[0]) - s2 = pd.Series(range(1, 4), name=names[1]) - result = pd.crosstab(s1, s2) - result_col_list = list(result.columns) - assert result_col_list == [1, 2, 3] + rows = [[1, 2, 3, 4], [1, 1, 2, 2], [1, 3, 1, 4]] + cols = [[1, 1, 1, 1], [3, 2, 2, 3], []] - s1 = pd.Series(range(0), name=names[0]) - s2 = pd.Series(range(1, 4), name=names[1]) - result = pd.crosstab(s1, s2) - result_col_list = list(result.columns) - assert result_col_list == [] + expected_ct1 = pd.DataFrame( + [1, 1, 1, 1], + index=pd.Index([1, 2, 3, 4], name=names[0]), + columns=pd.Index([1], name=names[1]) + ) + expected_ct2 = pd.DataFrame( + [[1, 1],[1, 1]], + index=pd.Index([1, 2], name=names[0]), + columns=pd.Index([2, 3], name=names[1]) + ) + expected_ct3 = pd.DataFrame([]) + expected_arr = [expected_ct1, expected_ct2, expected_ct3] + + for row, col, expected_data in zip(rows, cols, expected_arr): + s1 = pd.Series(row, name=names[0]) + s2 = pd.Series(col, name=names[1]) + result = pd.crosstab(s1, s2) + tm.assert_frame_equal(result, expected_data, + check_column_type=True) From cc0b9baffafcf883821c7e4778fa5160d98e37d9 Mon Sep 17 00:00:00 2001 From: Tuan Date: Tue, 23 Jan 2018 21:41:51 +1100 Subject: [PATCH 10/14] fix pep8 --- 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 37fab82d7b5f1..e0edbe9fc6ead 100644 --- a/pandas/core/reshape/pivot.py +++ b/pandas/core/reshape/pivot.py @@ -469,7 +469,7 @@ def crosstab(index, columns, values=None, rownames=None, colnames=None, dropna=dropna, **kwargs) if not table.empty: - added_cols_idx= list(df.columns.difference(common_cols_idx))[0] + added_cols_idx = list(df.columns.difference(common_cols_idx))[0] table = table[added_cols_idx] # Post-process diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index 4b8b564ea1abe..2b740000f63bf 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -1654,7 +1654,7 @@ def test_crosstab_cols_output(self, names): columns=pd.Index([1], name=names[1]) ) expected_ct2 = pd.DataFrame( - [[1, 1],[1, 1]], + [[1, 1], [1, 1]], index=pd.Index([1, 2], name=names[0]), columns=pd.Index([2, 3], name=names[1]) ) From ae553269207df46b6d546184456a93c9f4ffe2f7 Mon Sep 17 00:00:00 2001 From: Tuan Date: Wed, 24 Jan 2018 21:04:44 +1100 Subject: [PATCH 11/14] pull request 4 with updated doc, parametrized tests and comments in code logic --- doc/source/whatsnew/v0.23.0.txt | 2 +- pandas/core/reshape/pivot.py | 2 ++ pandas/tests/reshape/test_pivot.py | 40 +++++++++++------------------- 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/doc/source/whatsnew/v0.23.0.txt b/doc/source/whatsnew/v0.23.0.txt index ab3366354d68c..6ffafe2fae9c7 100644 --- a/doc/source/whatsnew/v0.23.0.txt +++ b/doc/source/whatsnew/v0.23.0.txt @@ -509,7 +509,7 @@ Reshaping - Bug in :func:`DataFrame.merge` in which merging using ``Index`` objects as vectors raised an Exception (:issue:`19038`) - Bug in :func:`DataFrame.stack`, :func:`DataFrame.unstack`, :func:`Series.unstack` which were not returning subclasses (:issue:`15563`) - Bug in timezone comparisons, manifesting as a conversion of the index to UTC in ``.concat()`` (:issue:`18523`) -- Bug in :func:`crosstab` where the added column is removed incorrectly (:issue:`18321`) +- Bug in :func:`crosstab` when performing crosstab operation on two series with tupple name, the resulting data frame has incorrectly named output columns (:issue:`18321`) - Numeric diff --git a/pandas/core/reshape/pivot.py b/pandas/core/reshape/pivot.py index e0edbe9fc6ead..4a2f39fcab4a3 100644 --- a/pandas/core/reshape/pivot.py +++ b/pandas/core/reshape/pivot.py @@ -457,6 +457,7 @@ def crosstab(index, columns, values=None, rownames=None, colnames=None, df = DataFrame(data, index=common_idx) common_cols_idx = df.columns + # adding dummy column for calculation of pivot table if values is None: df['__dummy__'] = 0 kwargs = {'aggfunc': len, 'fill_value': 0} @@ -468,6 +469,7 @@ def crosstab(index, columns, values=None, rownames=None, colnames=None, margins=margins, margins_name=margins_name, dropna=dropna, **kwargs) + # since column dummy is before computing pivot table, it has to be removed if not table.empty: added_cols_idx = list(df.columns.difference(common_cols_idx))[0] table = table[added_cols_idx] diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index 2b740000f63bf..93841ee0071e7 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -1640,30 +1640,18 @@ def test_crosstab_tuple_name(self, names): result = pd.crosstab(s1, s2) tm.assert_frame_equal(result, expected) - @pytest.mark.parametrize("names", [['a', 'b'], - [('a', 'b'), 'c'], - [('a', 'b'), ('c', 'd')], - [(1, 2, 3), ('a', 'b', 'c')]]) - def test_crosstab_cols_output(self, names): - rows = [[1, 2, 3, 4], [1, 1, 2, 2], [1, 3, 1, 4]] - cols = [[1, 1, 1, 1], [3, 2, 2, 3], []] - - expected_ct1 = pd.DataFrame( - [1, 1, 1, 1], - index=pd.Index([1, 2, 3, 4], name=names[0]), - columns=pd.Index([1], name=names[1]) - ) - expected_ct2 = pd.DataFrame( - [[1, 1], [1, 1]], - index=pd.Index([1, 2], name=names[0]), - columns=pd.Index([2, 3], name=names[1]) + @pytest.mark.parametrize("names, input_data, expected_data_out", [ + (['a', 'b'], [[1, 2, 3], [1, 1, 1]], [1, 1, 1]), + ([('a', 'b'), 'c'], [[1, 2, 2], [1, 1, 1]], [1, 2]), + ([('a', 'b'), ('c', 'd')], [[1, 2, 3], [1, 2, 3]], np.eye(3, dtype=int)) + ]) + def test_crosstab_cols_output(self, names, input_data, expected_data_out): + row_series = pd.Series(input_data[0], name=names[0]) + col_series = pd.Series(input_data[1], name=names[1]) + expected_crosstab = pd.DataFrame( + expected_data_out, + index=pd.Index(set(input_data[0]), name=names[0]), + columns=pd.Index(set(input_data[1]), name=names[1]) ) - expected_ct3 = pd.DataFrame([]) - expected_arr = [expected_ct1, expected_ct2, expected_ct3] - - for row, col, expected_data in zip(rows, cols, expected_arr): - s1 = pd.Series(row, name=names[0]) - s2 = pd.Series(col, name=names[1]) - result = pd.crosstab(s1, s2) - tm.assert_frame_equal(result, expected_data, - check_column_type=True) + tm.assert_frame_equal( + pd.crosstab(row_series, col_series), expected_crosstab) From a914b15d53e8fb0ab98c28383108383c951d56ea Mon Sep 17 00:00:00 2001 From: Tuan Date: Wed, 24 Jan 2018 21:13:47 +1100 Subject: [PATCH 12/14] fix pep8 --- pandas/tests/reshape/test_pivot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index 93841ee0071e7..ec660b0d97739 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -1644,7 +1644,7 @@ def test_crosstab_tuple_name(self, names): (['a', 'b'], [[1, 2, 3], [1, 1, 1]], [1, 1, 1]), ([('a', 'b'), 'c'], [[1, 2, 2], [1, 1, 1]], [1, 2]), ([('a', 'b'), ('c', 'd')], [[1, 2, 3], [1, 2, 3]], np.eye(3, dtype=int)) - ]) + ]) def test_crosstab_cols_output(self, names, input_data, expected_data_out): row_series = pd.Series(input_data[0], name=names[0]) col_series = pd.Series(input_data[1], name=names[1]) From 81dd6c2e870833f7d25eb9ea8d5650a13aacf861 Mon Sep 17 00:00:00 2001 From: Tuan Date: Wed, 24 Jan 2018 21:15:16 +1100 Subject: [PATCH 13/14] fix pep8 again --- pandas/tests/reshape/test_pivot.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index ec660b0d97739..47a5f84e7d626 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -1641,10 +1641,10 @@ def test_crosstab_tuple_name(self, names): tm.assert_frame_equal(result, expected) @pytest.mark.parametrize("names, input_data, expected_data_out", [ - (['a', 'b'], [[1, 2, 3], [1, 1, 1]], [1, 1, 1]), - ([('a', 'b'), 'c'], [[1, 2, 2], [1, 1, 1]], [1, 2]), - ([('a', 'b'), ('c', 'd')], [[1, 2, 3], [1, 2, 3]], np.eye(3, dtype=int)) - ]) + (['a', 'b'], [[1, 2, 3], [1, 1, 1]], [1, 1, 1]), + ([('a', 'b'), 'c'], [[1, 2, 2], [1, 1, 1]], [1, 2]), + ([('a', 'b'), ('c', 'd')], [[1, 2, 3], [1, 2, 3]], + np.eye(3, dtype=int))]) def test_crosstab_cols_output(self, names, input_data, expected_data_out): row_series = pd.Series(input_data[0], name=names[0]) col_series = pd.Series(input_data[1], name=names[1]) From c0f1d2923afa771fe0add8f50ef562893a61acdf Mon Sep 17 00:00:00 2001 From: Tuan Date: Wed, 24 Jan 2018 21:31:17 +1100 Subject: [PATCH 14/14] fix test --- pandas/tests/reshape/test_pivot.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index 47a5f84e7d626..5a6e7cd4d9bb3 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -1654,4 +1654,6 @@ def test_crosstab_cols_output(self, names, input_data, expected_data_out): columns=pd.Index(set(input_data[1]), name=names[1]) ) tm.assert_frame_equal( - pd.crosstab(row_series, col_series), expected_crosstab) + pd.crosstab(row_series, col_series), expected_crosstab, + check_exact=True + )