Skip to content

Commit 87583dc

Browse files
committed
Moved
1 parent b20e12c commit 87583dc

File tree

3 files changed

+11
-18
lines changed

3 files changed

+11
-18
lines changed

pandas/core/arrays/base.py

+1-10
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,6 @@ def nbytes(self):
143143
def astype(self, dtype, copy=True):
144144
"""Cast to a NumPy array with 'dtype'.
145145
146-
The default implementation only allows casting to 'object' dtype.
147-
148146
Parameters
149147
----------
150148
dtype : str or dtype
@@ -159,14 +157,7 @@ def astype(self, dtype, copy=True):
159157
array : ndarray
160158
NumPy ndarray with 'dtype' for its dtype.
161159
"""
162-
np_dtype = np.dtype(dtype)
163-
164-
if np_dtype != 'object':
165-
msg = ("{} can only be coerced to 'object' dtype, "
166-
"not '{}'.").format(type(self).__name__, dtype)
167-
raise ValueError(msg)
168-
169-
return np.array(self, dtype=np_dtype, copy=copy)
160+
return np.array(self, dtype=dtype, copy=copy)
170161

171162
def isna(self):
172163
# type: () -> np.ndarray

pandas/tests/extension/__init__.py

Whitespace-only changes.

pandas/tests/extension_arrays/test_common.py renamed to pandas/tests/extension/test_common.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ def __init__(self, data):
1212
def __array__(self, dtype):
1313
return self.data
1414

15+
@property
16+
def dtype(self):
17+
return self.data.dtype
18+
1519

1620
def test_astype():
1721
arr = DummyArray(np.array([1, 2, 3]))
@@ -24,13 +28,11 @@ def test_astype():
2428
tm.assert_numpy_array_equal(result, expected)
2529

2630

27-
def test_astype_raises():
28-
arr = DummyArray(np.array([1, 2, 3]))
31+
def test_astype_no_copy():
32+
arr = DummyArray(np.array([1, 2, 3], dtype=np.int64))
33+
result = arr.astype(arr.dtype, copy=False)
2934

30-
# type int for py2
31-
# class int for py3
32-
xpr = ("DummyArray can only be coerced to 'object' dtype, not "
33-
"'<.* 'int'>'")
35+
assert arr.data is result
3436

35-
with tm.assert_raises_regex(ValueError, xpr):
36-
arr.astype(int)
37+
result = arr.astype(arr.dtype)
38+
assert arr.data is not result

0 commit comments

Comments
 (0)