|
99 | 99 | Series, |
100 | 100 | ) |
101 | 101 | from pandas.core.arrays import ( |
| 102 | + ArrowExtensionArray, |
102 | 103 | BaseMaskedArray, |
103 | 104 | ExtensionArray, |
104 | 105 | ) |
@@ -1734,35 +1735,33 @@ def _build_map_infer_methods_params(arr: ArrayLike): |
1734 | 1735 | Values to be processed by lib.map_infer and lib.map_infer_mask |
1735 | 1736 |
|
1736 | 1737 | """ |
1737 | | - na_value = np.nan |
| 1738 | + na_value = None |
1738 | 1739 | mask = isna(arr) |
1739 | 1740 | storage = None |
| 1741 | + if ( |
| 1742 | + isinstance(arr.dtype, (BaseMaskedDtype, ExtensionDtype)) |
| 1743 | + and hasattr(arr, "_hasna") |
| 1744 | + and arr._hasna |
| 1745 | + ): |
| 1746 | + na_value = arr.dtype.na_value |
| 1747 | + |
1740 | 1748 | if isinstance(arr.dtype, BaseMaskedDtype): |
1741 | 1749 | arr = cast("BaseMaskedArray", arr) |
1742 | 1750 | values = np.fromiter(arr._data, dtype="O") |
1743 | | - if arr._hasna: |
1744 | | - na_value = arr.dtype.na_value |
1745 | 1751 |
|
1746 | 1752 | elif isinstance(arr.dtype, ExtensionDtype): |
1747 | | - from pandas.core.arrays.string_ import StringDtype |
1748 | | - |
1749 | 1753 | arr = cast("ExtensionArray", arr) |
1750 | | - arr_dtype = arr.dtype.__repr__() |
1751 | | - if ( |
1752 | | - isinstance(arr.dtype, StringDtype) and arr.dtype.storage == "pyarrow" |
1753 | | - ) or "pyarrow" in arr_dtype: |
1754 | | - storage = "pyarrow" |
| 1754 | + if hasattr(arr.dtype, "storage"): |
| 1755 | + storage = arr.dtype.storage |
| 1756 | + |
| 1757 | + if storage == "pyarrow": |
| 1758 | + arr = cast("ArrowExtensionArray", arr) |
1755 | 1759 | values = np.fromiter(arr._pa_array, dtype="O") |
1756 | 1760 | else: |
1757 | 1761 | values = np.asarray(arr) |
1758 | | - if ( |
1759 | | - isinstance(arr.dtype, StringDtype) and arr.dtype.storage == "python" |
1760 | | - ) or "python" in arr_dtype: |
1761 | | - storage = "python" |
1762 | | - if arr._hasna: |
1763 | | - na_value = arr.dtype.na_value |
1764 | 1762 |
|
1765 | 1763 | else: |
1766 | 1764 | # we must convert to python types |
1767 | 1765 | values = arr.astype(object, copy=False) |
| 1766 | + na_value = np.nan |
1768 | 1767 | return mask, na_value, storage, values |
0 commit comments