@@ -80,7 +80,8 @@ def split_result_of_axis_func_pandas(axis, num_splits, result, length_list=None)
80
80
Splitted dataframe represented by list of frames.
81
81
"""
82
82
if num_splits == 1 :
83
- return [result ]
83
+ yield result
84
+ return
84
85
85
86
if length_list is None :
86
87
length_list = get_length_list (result .shape [axis ], num_splits )
@@ -89,24 +90,21 @@ def split_result_of_axis_func_pandas(axis, num_splits, result, length_list=None)
89
90
90
91
sums = np .cumsum (length_list )
91
92
axis = 0 if isinstance (result , pandas .Series ) else axis
92
- # We do this to restore block partitioning
93
- if axis == 0 :
94
- chunked = [result .iloc [sums [i ] : sums [i + 1 ]] for i in range (len (sums ) - 1 )]
95
- else :
96
- chunked = [result .iloc [:, sums [i ] : sums [i + 1 ]] for i in range (len (sums ) - 1 )]
97
93
98
- return [
94
+ for i in range (len (sums ) - 1 ):
95
+ # We do this to restore block partitioning
96
+ if axis == 0 :
97
+ chunk = result .iloc [sums [i ] : sums [i + 1 ]]
98
+ else :
99
+ chunk = result .iloc [:, sums [i ] : sums [i + 1 ]]
100
+
99
101
# Sliced MultiIndex still stores all encoded values of the original index, explicitly
100
102
# asking it to drop unused values in order to save memory.
101
- (
102
- chunk .set_axis (
103
+ if isinstance ( chunk . axes [ axis ], pandas . MultiIndex ):
104
+ chunk = chunk .set_axis (
103
105
chunk .axes [axis ].remove_unused_levels (), axis = axis , copy = False
104
106
)
105
- if isinstance (chunk .axes [axis ], pandas .MultiIndex )
106
- else chunk
107
- )
108
- for chunk in chunked
109
- ]
107
+ yield chunk
110
108
111
109
112
110
def get_length_list (axis_len : int , num_splits : int ) -> list :
0 commit comments