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

BUG: Regression in astype not casting to bytes #39484

Merged
merged 2 commits into from
Feb 2, 2021
Merged

Conversation

phofl
Copy link
Member

@phofl phofl commented Jan 30, 2021

Not sure if this is the right place

def test_astype_bytes(self):
# GH#39474
result = DataFrame(["foo", "bar", "baz"]).astype(bytes)
assert result.dtypes[0] == np.dtype("S3")
Copy link
Contributor

Choose a reason for hiding this comment

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

this is not correct, it should be object

Copy link
Member Author

@phofl phofl Jan 30, 2021

Choose a reason for hiding this comment

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

This was np.dtype("S3") on 1.1.5 too, so wrong there too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Could remove the test to avoid testing wrong behavior?

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm yeah this is definitely wrong, we should never have a numpy string type in output.

Copy link
Member

Choose a reason for hiding this comment

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

We have unfortunately been doing this for many releases ..

Copy link
Contributor

Choose a reason for hiding this comment

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

grr really?

Copy link
Contributor

Choose a reason for hiding this comment

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

ok @phofl let's fix this for 1.3 (the S dtypes) and backport this change.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok all right. Will open issue as follow up

@@ -2247,7 +2247,7 @@ class ObjectBlock(Block):
_can_hold_na = True

def _maybe_coerce_values(self, values):
if issubclass(values.dtype.type, (str, bytes)):
if issubclass(values.dtype.type, str):
Copy link
Contributor

Choose a reason for hiding this comment

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

why are you changing this?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have added this in #39065, which caused the regression. have to handle the replace issue at another place

Copy link
Contributor

Choose a reason for hiding this comment

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

oh i

@jreback jreback added this to the 1.2.2 milestone Jan 30, 2021
@jreback jreback added Regression Functionality that used to work in a prior pandas version Strings String extension data type and string data labels Jan 30, 2021
@@ -2247,7 +2247,7 @@ class ObjectBlock(Block):
_can_hold_na = True

def _maybe_coerce_values(self, values):
if issubclass(values.dtype.type, (str, bytes)):
if issubclass(values.dtype.type, str):
Copy link
Contributor

Choose a reason for hiding this comment

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

oh i

def test_astype_bytes(self):
# GH#39474
result = DataFrame(["foo", "bar", "baz"]).astype(bytes)
assert result.dtypes[0] == np.dtype("S3")
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm yeah this is definitely wrong, we should never have a numpy string type in output.

@jreback
Copy link
Contributor

jreback commented Feb 2, 2021

@phofl if you'd merge master

@phofl
Copy link
Member Author

phofl commented Feb 2, 2021

merged master

@phofl
Copy link
Member Author

phofl commented Feb 2, 2021

Opened #39566

@jreback jreback merged commit 300d1fc into pandas-dev:master Feb 2, 2021
@jreback
Copy link
Contributor

jreback commented Feb 2, 2021

thanks @phofl

@jreback
Copy link
Contributor

jreback commented Feb 2, 2021

@meeseeksdev backport 1.2.x

@phofl phofl deleted the 39474 branch February 2, 2021 22:15
@lumberbot-app
Copy link

lumberbot-app bot commented Feb 2, 2021

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
$ git checkout 1.2.x
$ git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
$ git cherry-pick -m1 300d1fcafb02e822893d335bde890011a415ddf7
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
$ git commit -am 'Backport PR #39484: BUG: Regression in astype not casting to bytes'
  1. Push to a named branch :
git push YOURFORK 1.2.x:auto-backport-of-pr-39484-on-1.2.x
  1. Create a PR against branch 1.2.x, I would have named this PR:

"Backport PR #39484 on branch 1.2.x"

And apply the correct labels and milestones.

Congratulation you did some good work ! Hopefully your backport PR will be tested by the continuous integration and merged soon!

If these instruction are inaccurate, feel free to suggest an improvement.

phofl added a commit to phofl/pandas that referenced this pull request Feb 2, 2021
jreback pushed a commit that referenced this pull request Feb 2, 2021
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Regression Functionality that used to work in a prior pandas version Strings String extension data type and string data
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Regression cannot create Series with dtype 'S|' or 'bytes'
3 participants