forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(cherry picked from commit 943a915562b72bed147c857de927afa0daf31c1a)
- Loading branch information
1 parent
b835127
commit fbf0a06
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import numpy as np | ||
|
||
import pandas.util.testing as tm | ||
from pandas.core.arrays import ExtensionArray | ||
|
||
|
||
class DummyArray(ExtensionArray): | ||
|
||
def __init__(self, data): | ||
self.data = data | ||
|
||
def __array__(self, dtype): | ||
return self.data | ||
|
||
|
||
def test_astype(): | ||
arr = DummyArray(np.array([1, 2, 3])) | ||
expected = np.array([1, 2, 3], dtype=object) | ||
|
||
result = arr.astype(object) | ||
tm.assert_numpy_array_equal(result, expected) | ||
|
||
result = arr.astype('object') | ||
tm.assert_numpy_array_equal(result, expected) | ||
|
||
|
||
def test_astype_raises(): | ||
arr = DummyArray(np.array([1, 2, 3])) | ||
|
||
xpr = ("DummyArray can only be coerced to 'object' dtype, not " | ||
"'<class 'int'>'") | ||
|
||
with tm.assert_raises_regex(ValueError, xpr): | ||
arr.astype(int) |