Skip to content

Commit 16e70cc

Browse files
committed
fix map method, hopefully doesn't break other things...
1 parent 2c46b75 commit 16e70cc

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

pandas/_libs/lib.pyx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ from cython cimport (
3939

4040
from pandas._config import using_pyarrow_string_dtype
4141

42-
from pandas._libs.missing import check_na_tuples_nonequal
42+
from pandas._libs.missing import check_na_tuples_nonequal, NA
43+
44+
from pandas.compat.numpy import np_version_gt2
4345

4446
import_datetime()
4547

@@ -2625,7 +2627,7 @@ def maybe_convert_objects(ndarray[object] objects,
26252627
seen.object_ = True
26262628
break
26272629
elif isinstance(val, str):
2628-
if convert_non_numeric:
2630+
if convert_non_numeric or np_version_gt2:
26292631
seen.str_ = True
26302632
break
26312633
else:
@@ -2704,6 +2706,9 @@ def maybe_convert_objects(ndarray[object] objects,
27042706

27052707
dtype = StringDtype()
27062708
return dtype.construct_array_type()._from_sequence(objects, dtype=dtype)
2709+
elif np_version_gt2:
2710+
dtype = np.dtypes.StringDType(na_object=NA, coerce=False)
2711+
return np.array(objects, dtype=dtype)
27072712

27082713
seen.object_ = True
27092714
elif seen.interval_:

pandas/core/algorithms.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
from pandas.util._decorators import doc
3636
from pandas.util._exceptions import find_stack_level
3737

38+
from pandas.compat.numpy import np_version_gt2
39+
3840
from pandas.core.dtypes.cast import (
3941
construct_1d_object_array_from_listlike,
4042
np_find_common_type,
@@ -1645,6 +1647,7 @@ def map_array(
16451647
If the function returns a tuple with more than one element
16461648
a MultiIndex will be returned.
16471649
"""
1650+
from pandas.core.arrays.string_ import StringArray
16481651
if na_action not in (None, "ignore"):
16491652
msg = f"na_action must either be 'ignore' or None, {na_action} was passed"
16501653
raise ValueError(msg)
@@ -1693,6 +1696,7 @@ def map_array(
16931696

16941697
# we must convert to python types
16951698
values = arr.astype(object, copy=False)
1699+
16961700
if na_action is None:
16971701
return lib.map_infer(values, mapper)
16981702
else:

0 commit comments

Comments
 (0)