Conversation

phofl
  • closes #xxxx (Replace xxxx with the 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.

@mroeschkemroeschke added Dtype ConversionsUnexpected or buggy dtype conversionsStringsString extension data type and string datalabels Nov 26, 2023
@mroeschkemroeschke added this to the 2.2 milestone Nov 26, 2023
@mroeschkemroeschke merged commit 99bcf6b into pandas-dev:main Nov 26, 2023
@mroeschke

Thanks @phofl

@phoflphofl deleted the string_accessor branch November 26, 2023 18:23
@phofl

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

@phoflphofl modified the milestones: 2.2, 2.1.4 Nov 26, 2023
@phofl

@meeseeksdev backport 2.1.x

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 <[email protected]>
Sign up for free to join this conversation on . Already have an account? Sign in to comment
Dtype ConversionsUnexpected or buggy dtype conversionsStringsString extension data type and string data
None yet

Successfully merging this pull request may close these issues.