@@ -31,11 +31,6 @@ def pivot_table(data, values=None, index=None, columns=None, aggfunc='mean',
31
31
index = _convert_by (index )
32
32
columns = _convert_by (columns )
33
33
34
- num_rows = data .reindex (index , axis = 'columns' ).shape [0 ]
35
- num_columns = data .reindex (columns , axis = 'columns' ).shape [0 ]
36
- if num_rows * num_columns > (2 ** 31 - 1 ):
37
- raise ValueError ('Pivot table is too big, causing int32 overflow' )
38
-
39
34
if isinstance (aggfunc , list ):
40
35
pieces = []
41
36
keys = []
@@ -86,9 +81,14 @@ def pivot_table(data, values=None, index=None, columns=None, aggfunc='mean',
86
81
pass
87
82
values = list (values )
88
83
89
- # group by the cartesian product of the grouper
90
- # if we have a categorical
91
- grouped = data .groupby (keys , observed = False )
84
+ num_rows = (data .reindex (columns = index ).drop_duplicates ().shape [0 ]
85
+ if index else 1 )
86
+ num_cols = (data .reindex (columns = columns ).drop_duplicates ().shape [0 ]
87
+ if columns else 1 )
88
+ if num_rows * num_cols * len (values ) > (2 ** 31 - 1 ):
89
+ raise ValueError ('Pivot table is too big, causing int32 overflow' )
90
+
91
+ grouped = data .groupby (keys )
92
92
agged = grouped .agg (aggfunc )
93
93
if dropna and isinstance (agged , ABCDataFrame ) and len (agged .columns ):
94
94
agged = agged .dropna (how = 'all' )
0 commit comments