-
-
Notifications
You must be signed in to change notification settings - Fork 18k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API: Default ExtensionArray.astype #19604
API: Default ExtensionArray.astype #19604
Conversation
(cherry picked from commit 943a915562b72bed147c857de927afa0daf31c1a)
Codecov Report
@@ Coverage Diff @@
## master #19604 +/- ##
==========================================
- Coverage 91.62% 91.6% -0.03%
==========================================
Files 150 150
Lines 48790 48798 +8
==========================================
- Hits 44703 44699 -4
- Misses 4087 4099 +12
Continue to review full report at Codecov.
|
pandas/core/arrays/base.py
Outdated
""" | ||
np_dtype = np.dtype(dtype) | ||
|
||
if np_dtype != 'object': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use is_object_dtype
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you even need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean the check for object? Fair point. If the underlying object supports conversion to whatever format, we should allow it.
In [1]: import pandas_ip as ip
In [2]: ip.IPAddress([1, 2, 3]).astype(object)
Out[2]:
array([IPv4Address('0.0.0.1'), IPv4Address('0.0.0.2'),
IPv4Address('0.0.0.3')], dtype=object)
In [3]: ip.IPAddress([1, 2, 3]).astype(int)
Out[3]: array([1, 2, 3])
Which simplifies things nicely!
@@ -0,0 +1,36 @@ | |||
import numpy as np |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put this in pandas/tests/extension/test_common.py
you also need an __init__.py
import numpy as np | ||
|
||
import pandas.util.testing as tm | ||
from pandas.core.arrays import ExtensionArray |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would also move the existing extension tests here
cc @jorisvandenbossche if you have thoughts. This now just does |
* API: Default ExtensionArray.astype (cherry picked from commit 943a915562b72bed147c857de927afa0daf31c1a) * Py2 compat * Moved * Moved dtypes
I need this to progress cleanly on #19558 and (which is blocking #19520).