Skip to content

BUG: astype(Int64) raises AttributeError #22869

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

Merged
merged 1 commit into from
Oct 10, 2018
Merged

Conversation

sinhrks
Copy link
Member

@sinhrks sinhrks commented Sep 28, 2018

@pep8speaks
Copy link

Hello @sinhrks! Thanks for submitting the PR.

@sinhrks sinhrks added Bug ExtensionArray Extending pandas with custom dtypes or arrays. labels Sep 28, 2018
@@ -671,15 +671,6 @@ def _astype(self, dtype, copy=False, errors='raise', values=None,
raise
newb = self.copy() if copy else self

if newb.is_numeric and self.is_numeric:
if newb.shape != self.shape:
Copy link
Member Author

Choose a reason for hiding this comment

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

Does anyone know what case meets the condition?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think .astype('i1') on an int64 might hit this

Copy link
Member Author

@sinhrks sinhrks Oct 1, 2018

Choose a reason for hiding this comment

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

Thx. It looks work (might depending on OS?)

pd.DataFrame([1]).astype('i1')

To keep the error condition for safety, remove itemsize from the error message? (or add .itemsize to extension dtypes)

pd.Series([1], dtype='int64').dtype.itemsize
# 8
pd.Series([1], dtype='Int64').dtype.itemsize
# AttributeError: 'Int64Dtype' object has no attribute 'itemsize'

@jreback jreback added this to the 0.24.0 milestone Oct 7, 2018
@jreback
Copy link
Contributor

jreback commented Oct 7, 2018

looks good. can you add on the issue to the whatsnew for integer array (just add to the list), and rebase.

@@ -675,11 +675,11 @@ def _astype(self, dtype, copy=False, errors='raise', values=None,
if newb.shape != self.shape:
raise TypeError(
"cannot set astype for copy = [{copy}] for dtype "
"({dtype} [{itemsize}]) with smaller itemsize than "
"current ({newb_dtype} [{newb_size}])".format(
"({dtype} [{shape}]) to different shape "
Copy link
Member Author

Choose a reason for hiding this comment

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

Changed the message not to raise AttributeError.

@sinhrks
Copy link
Member Author

sinhrks commented Oct 9, 2018

Thx for the review. Updated and rebased.

@jreback
Copy link
Contributor

jreback commented Oct 9, 2018

seems there is a lint error.

@codecov
Copy link

codecov bot commented Oct 10, 2018

Codecov Report

Merging #22869 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #22869   +/-   ##
=======================================
  Coverage   92.19%   92.19%           
=======================================
  Files         169      169           
  Lines       50911    50911           
=======================================
  Hits        46939    46939           
  Misses       3972     3972
Flag Coverage Δ
#multiple 90.61% <100%> (ø) ⬆️
#single 42.3% <100%> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/internals/blocks.py 93.48% <ø> (ø) ⬆️
pandas/core/generic.py 96.65% <100%> (ø) ⬆️

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 f6da1f1...cb849ca. Read the comment docs.

@sinhrks
Copy link
Member Author

sinhrks commented Oct 10, 2018

Sorry, fixed.

@jreback jreback merged commit db399c2 into pandas-dev:master Oct 10, 2018
@jreback
Copy link
Contributor

jreback commented Oct 10, 2018

thanks!

tm9k1 pushed a commit to tm9k1/pandas that referenced this pull request Nov 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug ExtensionArray Extending pandas with custom dtypes or arrays.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: astype('Int64') raises AttributeError
3 participants