Commit f8153f3
committed
Fix #60766:.map,.apply would convert element type for extension array.
The Int32Dtype type allows representing integers with support for null
values (pd.NA). However, when using .map(f) or .apply(f), the elements
passed to f are converted to float64, and pd.NA is transformed into
np.nan.
This happens because .map() and .apply() internally use numpy, which
automatically converts the data to float64, even when the original type is
Int32Dtype.
The fix (just remove the method to_numpy()) ensures that when using
.map() or .apply(), the elements in the series retain their original type
(Int32, Float64, boolean, etc.), preventing unnecessary conversions to
float64 and ensuring that pd.NA remains correctly handled.1 parent b64f438 commit f8153f3
File tree
2 files changed
+19
-1
lines changed- pandas
- core/arrays
- tests/arrays/masked
2 files changed
+19
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1325 | 1325 | | |
1326 | 1326 | | |
1327 | 1327 | | |
1328 | | - | |
| 1328 | + | |
1329 | 1329 | | |
1330 | 1330 | | |
1331 | 1331 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
0 commit comments