Skip to content
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

Merged

Conversation

TomAugspurger
Copy link
Contributor

I need this to progress cleanly on #19558 and (which is blocking #19520).

(cherry picked from commit 943a915562b72bed147c857de927afa0daf31c1a)
@TomAugspurger TomAugspurger added API Design Internals Related to non-user accessible pandas implementation labels Feb 8, 2018
@TomAugspurger TomAugspurger added this to the 0.23.0 milestone Feb 8, 2018
@codecov
Copy link

codecov bot commented Feb 8, 2018

Codecov Report

Merging #19604 into master will decrease coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 89.97% <100%> (-0.03%) ⬇️
#single 41.73% <66.66%> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/core/arrays/base.py 60.6% <100%> (+3.93%) ⬆️
pandas/plotting/_converter.py 65.22% <0%> (-1.74%) ⬇️
pandas/core/frame.py 97.42% <0%> (ø) ⬆️
pandas/io/formats/format.py 96.25% <0%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b835127...d136227. Read the comment docs.

"""
np_dtype = np.dtype(dtype)

if np_dtype != 'object':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use is_object_dtype

Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor

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

@TomAugspurger
Copy link
Contributor Author

TomAugspurger commented Feb 9, 2018

cc @jorisvandenbossche if you have thoughts.

This now just does np.array. It'll work if the underlying items can be converted to dtype.

@TomAugspurger TomAugspurger merged commit 6485a36 into pandas-dev:master Feb 9, 2018
@TomAugspurger TomAugspurger deleted the extensionarray-astype branch February 9, 2018 20:53
harisbal pushed a commit to harisbal/pandas that referenced this pull request Feb 28, 2018
* API: Default ExtensionArray.astype

(cherry picked from commit 943a915562b72bed147c857de927afa0daf31c1a)

* Py2 compat

* Moved

* Moved dtypes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Internals Related to non-user accessible pandas implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants