MCPcopy
hub / github.com/pandas-dev/pandas / wrap_results_for_axis

Method wrap_results_for_axis

pandas/core/apply.py:1299–1338  ·  view source on GitHub ↗

return the results for the rows

(
        self, results: ResType, res_index: Index
    )

Source from the content-addressed store, hash-verified

1297 return self.index
1298
1299 def wrap_results_for_axis(
1300 self, results: ResType, res_index: Index
1301 ) -> DataFrame | Series:
1302 """return the results for the rows"""
1303
1304 if self.result_type == "reduce":
1305 # e.g. test_apply_dict GH#8735
1306 res = self.obj._constructor_sliced(results)
1307 res.index = res_index
1308 return res
1309
1310 elif self.result_type is None and all(
1311 isinstance(x, dict) for x in results.values()
1312 ):
1313 # Our operation was a to_dict op e.g.
1314 # test_apply_dict GH#8735, test_apply_reduce_to_dict GH#25196 #37544
1315 res = self.obj._constructor_sliced(results)
1316 res.index = res_index
1317 return res
1318
1319 try:
1320 result = self.obj._constructor(data=results)
1321 except ValueError as err:
1322 if "All arrays must be of the same length" in str(err):
1323 # e.g. result = [[2, 3], [1.5], ['foo', 'bar']]
1324 # see test_agg_listlike_result GH#29587
1325 res = self.obj._constructor_sliced(results)
1326 res.index = res_index
1327 return res
1328 else:
1329 raise
1330
1331 if not isinstance(results[0], ABCSeries):
1332 if len(result.index) == len(self.res_columns):
1333 result.index = self.res_columns
1334
1335 if len(result.columns) == len(res_index):
1336 result.columns = res_index
1337
1338 return result
1339
1340
1341class FrameColumnApply(FrameApply):

Callers

nothing calls this directly

Calls 3

_constructor_slicedMethod · 0.45
valuesMethod · 0.45
_constructorMethod · 0.45

Tested by

no test coverage detected