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: preserve (object) dtype in factorize #60118

Merged

Conversation

jorisvandenbossche
Copy link
Member

Noticed this issue in #60116 (which adds an xfail for it):

>>> pd.options.future.infer_string = True
>>> idx = pd.Index(["string", "with", "object", "dtype"], dtype=object)
>>> idx
Index(['string', 'with', 'object', 'dtype'], dtype='object')
>>> idx.factorize()
(array([0, 1, 2, 3]),
 Index(['string', 'with', 'object', 'dtype'], dtype='str'))    # <--- now str dtype

I think in general a function like factorize should preserve the dtype, even though a better dtype could be inferred here.

@jorisvandenbossche jorisvandenbossche added Dtype Conversions Unexpected or buggy dtype conversions Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff labels Oct 28, 2024
@jorisvandenbossche jorisvandenbossche marked this pull request as ready for review October 31, 2024 09:10
@mroeschke mroeschke added this to the 2.3 milestone Oct 31, 2024
@mroeschke mroeschke merged commit 13926e5 into pandas-dev:main Oct 31, 2024
51 checks passed
@mroeschke
Copy link
Member

Thanks @jorisvandenbossche

Copy link

lumberbot-app bot commented Oct 31, 2024

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 2.3.x
git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 13926e5e298acf328b0c1347f008ef3f9c4eb078
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #60118: BUG: preserve (object) dtype in factorize'
  1. Push to a named branch:
git push YOURFORK 2.3.x:auto-backport-of-pr-60118-on-2.3.x
  1. Create a PR against branch 2.3.x, I would have named this PR:

"Backport PR #60118 on branch 2.3.x (BUG: preserve (object) dtype in factorize)"

And apply the correct labels and milestones.

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

Remember to remove the Still Needs Manual Backport label once the PR gets merged.

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

@jorisvandenbossche jorisvandenbossche deleted the factorize-preserve-dtype branch November 4, 2024 06:12
jorisvandenbossche added a commit to jorisvandenbossche/pandas that referenced this pull request Nov 4, 2024
* BUG: preserve (object) dtype in factorize

* add fallback for float16

(cherry picked from commit 13926e5)
@jorisvandenbossche
Copy link
Member Author

Manual backport -> #60174

jorisvandenbossche added a commit that referenced this pull request Nov 4, 2024
…60174)

BUG: preserve (object) dtype in factorize (#60118)

* BUG: preserve (object) dtype in factorize

* add fallback for float16

(cherry picked from commit 13926e5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Dtype Conversions Unexpected or buggy dtype conversions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants