Skip to content

Commit 7954a81

Browse files
committed
use asarray and remove conditions from base.py
1 parent 70ac3b3 commit 7954a81

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

pandas/core/arrays/base.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,11 @@ def try_cast_to_ea(cls_or_instance, obj, dtype=None):
5151
-------
5252
ExtensionArray or obj
5353
"""
54-
if not (
55-
is_integer_dtype(cls_or_instance)
56-
and is_bool(obj[0])
57-
and not hasattr(cls_or_instance, "sp_values")
58-
):
59-
try:
60-
result = cls_or_instance._from_sequence(obj, dtype=dtype)
61-
except Exception:
62-
# We can't predict what downstream EA constructors may raise
63-
result = obj
64-
else:
65-
return obj
54+
try:
55+
result = cls_or_instance._from_sequence(obj, dtype=dtype)
56+
except Exception:
57+
# We can't predict what downstream EA constructors may raise
58+
result = obj
6659
return result
6760

6861

pandas/core/arrays/integer.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,9 @@ def coerce_to_array(values, dtype, mask=None, copy=False):
196196
mask = mask.copy()
197197
return values, mask
198198

199-
if hasattr(values, "dtype"):
200-
values = np.array(values, copy=copy)
201-
else:
202-
values = np.array(values, dtype=object, copy=copy)
199+
values = np.asarray(values, dtype=getattr(values, "dtype", object))
200+
if copy:
201+
values = values.copy()
203202

204203
if is_object_dtype(values):
205204
inferred_type = lib.infer_dtype(values, skipna=True)

0 commit comments

Comments
 (0)