Skip to content

Commit

Permalink
Moved
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAugspurger committed Feb 9, 2018
1 parent b20e12c commit 87583dc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
11 changes: 1 addition & 10 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ def nbytes(self):
def astype(self, dtype, copy=True):
"""Cast to a NumPy array with 'dtype'.
The default implementation only allows casting to 'object' dtype.
Parameters
----------
dtype : str or dtype
Expand All @@ -159,14 +157,7 @@ def astype(self, dtype, copy=True):
array : ndarray
NumPy ndarray with 'dtype' for its dtype.
"""
np_dtype = np.dtype(dtype)

if np_dtype != 'object':
msg = ("{} can only be coerced to 'object' dtype, "
"not '{}'.").format(type(self).__name__, dtype)
raise ValueError(msg)

return np.array(self, dtype=np_dtype, copy=copy)
return np.array(self, dtype=dtype, copy=copy)

def isna(self):
# type: () -> np.ndarray
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def __init__(self, data):
def __array__(self, dtype):
return self.data

@property
def dtype(self):
return self.data.dtype


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


def test_astype_raises():
arr = DummyArray(np.array([1, 2, 3]))
def test_astype_no_copy():
arr = DummyArray(np.array([1, 2, 3], dtype=np.int64))
result = arr.astype(arr.dtype, copy=False)

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

with tm.assert_raises_regex(ValueError, xpr):
arr.astype(int)
result = arr.astype(arr.dtype)
assert arr.data is not result

0 comments on commit 87583dc

Please sign in to comment.