Skip to content

Commit 8af4cda

Browse files
fixup allow_2d
1 parent c56c5f5 commit 8af4cda

File tree

3 files changed

+7
-21
lines changed

3 files changed

+7
-21
lines changed

pandas/core/arrays/datetimelike.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ def _validate_listlike(self, value, allow_object: bool = False):
669669

670670
# Do type inference if necessary up front
671671
# e.g. we passed PeriodIndex.values and got an ndarray of Periods
672-
value = sanitize_array(value, index=None)
672+
value = sanitize_array(value, index=None, allow_2d=True)
673673
value = ensure_wrapped_if_datetimelike(value)
674674

675675
if is_all_strings(value):

pandas/core/construction.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
from pandas.core.dtypes.common import (
3838
ensure_object,
3939
is_list_like,
40-
is_object_dtype,
4140
pandas_dtype,
4241
)
4342
from pandas.core.dtypes.dtypes import NumpyEADtype
@@ -49,8 +48,6 @@
4948
)
5049
from pandas.core.dtypes.missing import isna
5150

52-
import pandas.core.common as com
53-
5451
if TYPE_CHECKING:
5552
from collections.abc import Sequence
5653

@@ -706,23 +703,12 @@ def _sanitize_ndim(
706703
result = _maybe_repeat(result, index)
707704

708705
elif result.ndim > 1:
709-
if isinstance(data, np.ndarray):
710-
if allow_2d:
711-
return result
712-
raise ValueError(
713-
f"Data must be 1-dimensional, got ndarray of shape {data.shape} instead"
714-
)
715-
if is_object_dtype(dtype) and isinstance(dtype, ExtensionDtype):
716-
# i.e. NumpyEADtype("O")
706+
if allow_2d:
707+
return result
708+
raise ValueError(
709+
f"Data must be 1-dimensional, got ndarray of shape {data.shape} instead"
710+
)
717711

718-
result = com.asarray_tuplesafe(data, dtype=np.dtype("object"))
719-
cls = dtype.construct_array_type()
720-
result = cls._from_sequence(result, dtype=dtype)
721-
else:
722-
# error: Argument "dtype" to "asarray_tuplesafe" has incompatible type
723-
# "Union[dtype[Any], ExtensionDtype, None]"; expected "Union[str,
724-
# dtype[Any], None]"
725-
result = com.asarray_tuplesafe(data, dtype=dtype) # type: ignore[arg-type]
726712
return result
727713

728714

pandas/tests/arrays/test_datetimelike.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ def test_searchsorted_castable_strings(
336336
match=re.escape(
337337
f"value should be a '{arr1d._scalar_type.__name__}', 'NaT', "
338338
"or array of those. Got "
339-
f"{'str' if using_infer_string else 'string'} array instead."
339+
f"{'str' if using_infer_string else 'object'} array instead."
340340
),
341341
):
342342
arr.searchsorted([str(arr[1]), "baz"])

0 commit comments

Comments
 (0)