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: translate losing object dtype with new string dtype #56152

Merged
merged 3 commits into from
Nov 26, 2023

Conversation

phofl
Copy link
Member

@phofl phofl commented Nov 24, 2023

  • closes #xxxx (Replace xxxx with the GitHub issue number)
  • Tests added and passed if fixing a bug or adding a new feature
  • All code checks passed.
  • Added type annotations to new arguments/methods/functions.
  • Added an entry in the latest doc/source/whatsnew/vX.X.X.rst file if fixing a bug or adding a new feature.

@@ -2317,7 +2318,8 @@ def translate(self, table):
dtype: object
"""
result = self._data.array._str_translate(table)
return self._wrap_result(result)
dtype = object if self._data.dtype == "object" else None
return self._wrap_result(result, dtype=dtype)
Copy link
Member

@mroeschke mroeschke Nov 26, 2023

Choose a reason for hiding this comment

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

Maybe dumb question, but we can't just pass dtype=self._data.dtype and have the result dtype be correct in _wrap_result (with maybe additional logic)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Categoricals act out then, that's a bit confusing to me as well, but I didn't want to focus on this now.

@mroeschke mroeschke added Dtype Conversions Unexpected or buggy dtype conversions Strings String extension data type and string data labels Nov 26, 2023
@mroeschke mroeschke added this to the 2.2 milestone Nov 26, 2023
@mroeschke mroeschke merged commit 99bcf6b into pandas-dev:main Nov 26, 2023
46 checks passed
@mroeschke
Copy link
Member

Thanks @phofl

@phofl phofl deleted the string_accessor branch November 26, 2023 18:23
@phofl
Copy link
Member Author

phofl commented Nov 26, 2023

Sorry this was meant for 2.1.4, should have added the milestone

@phofl phofl modified the milestones: 2.2, 2.1.4 Nov 26, 2023
@phofl
Copy link
Member Author

phofl commented Nov 26, 2023

@meeseeksdev backport 2.1.x

meeseeksmachine pushed a commit to meeseeksmachine/pandas that referenced this pull request Nov 26, 2023
phofl added a commit that referenced this pull request Nov 26, 2023
…e with new string dtype) (#56185)

Backport PR #56152: BUG: translate losing object dtype with new string dtype

Co-authored-by: Patrick Hoefler <61934744+phofl@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dtype Conversions Unexpected or buggy dtype conversions Strings String extension data type and string data
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants