-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
Conversation
Hello @sinhrks! Thanks for submitting the PR.
|
pandas/core/internals/blocks.py
Outdated
@@ -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: |
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.
Does anyone know what case meets the condition?
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.
I think .astype('i1') on an int64 might hit 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.
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'
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 " |
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.
Changed the message not to raise AttributeError
.
Thx for the review. Updated and rebased. |
seems there is a lint error. |
Codecov Report
@@ Coverage Diff @@
## master #22869 +/- ##
=======================================
Coverage 92.19% 92.19%
=======================================
Files 169 169
Lines 50911 50911
=======================================
Hits 46939 46939
Misses 3972 3972
Continue to review full report at Codecov.
|
Sorry, fixed. |
thanks! |
git diff upstream/master -u -- "*.py" | flake8 --diff