@@ -137,24 +137,24 @@ def __init__(
137
137
self .removed_level = self .removed_level .take (unique_codes )
138
138
self .removed_level_full = self .removed_level_full .take (unique_codes )
139
139
140
- # Bug fix GH 20601
141
- # If the data frame is too big, the number of unique index combination
142
- # will cause int32 overflow on windows environments.
143
- # We want to check and raise an warning before this happens
144
- num_rows = np . max ([ index_level . size for index_level in self . new_index_levels ])
145
- num_columns = self . removed_level . size
146
-
147
- # GH20601: This forces an overflow if the number of cells is too high.
148
- num_cells = num_rows * num_columns
149
-
150
- # GH 26314: Previous ValueError raised was too restrictive for many users.
151
- if get_option ( "performance_warnings" ) and num_cells > np .iinfo (np .int32 ).max :
152
- warnings .warn (
153
- f"The following operation may generate { num_cells } cells "
154
- f"in the resulting pandas object." ,
155
- PerformanceWarning ,
156
- stacklevel = find_stack_level (),
157
- )
140
+ if get_option ( "performance_warnings" ):
141
+ # Bug fix GH 20601
142
+ # If the data frame is too big, the number of unique index combination
143
+ # will cause int32 overflow on windows environments.
144
+ # We want to check and raise an warning before this happens
145
+ num_rows = max ( index_level . size for index_level in self . new_index_levels )
146
+ num_columns = self . removed_level . size
147
+
148
+ # GH20601: This forces an overflow if the number of cells is too high.
149
+ # GH 26314: Previous ValueError raised was too restrictive for many users.
150
+ num_cells = num_rows * num_columns
151
+ if num_cells > np .iinfo (np .int32 ).max :
152
+ warnings .warn (
153
+ f"The following operation may generate { num_cells } cells "
154
+ f"in the resulting pandas object." ,
155
+ PerformanceWarning ,
156
+ stacklevel = find_stack_level (),
157
+ )
158
158
159
159
self ._make_selectors ()
160
160
@@ -731,10 +731,10 @@ def _stack_multi_column_index(columns: MultiIndex) -> MultiIndex | Index:
731
731
if len (columns .levels ) <= 2 :
732
732
return columns .levels [0 ]._rename (name = columns .names [0 ])
733
733
734
- levs = [
734
+ levs = (
735
735
[lev [c ] if c >= 0 else None for c in codes ]
736
736
for lev , codes in zip (columns .levels [:- 1 ], columns .codes [:- 1 ])
737
- ]
737
+ )
738
738
739
739
# Remove duplicate tuples in the MultiIndex.
740
740
tuples = zip (* levs )
0 commit comments