-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
String dtype: implement object-dtype based StringArray variant with NumPy semantics #58451
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
Merged
jorisvandenbossche
merged 18 commits into
pandas-dev:main
from
jorisvandenbossche:string-dtype-object
Aug 7, 2024
+231
−48
Merged
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
63a7fc5
String dtype: implement object-dtype based StringArray variant with N…
jorisvandenbossche 0eee625
fix constructor to not convert to NA
jorisvandenbossche 607b95e
fix typing
jorisvandenbossche bca157d
improve logic in str_map
jorisvandenbossche 79eb3b4
Merge remote-tracking branch 'upstream/main' into string-dtype-object
jorisvandenbossche c063298
Merge remote-tracking branch 'upstream/main' into string-dtype-object
jorisvandenbossche ab96aa4
remove most usage of python_numpy
jorisvandenbossche bae8d65
update tests to avoid string[python_numpy]
jorisvandenbossche 31f1c33
Merge remote-tracking branch 'upstream/main' into string-dtype-object
jorisvandenbossche cbd0820
Merge remote-tracking branch 'upstream/main' into string-dtype-object
jorisvandenbossche 864c166
remove all python_numpy usage
jorisvandenbossche d3ad7b0
remove hardcoded storage
jorisvandenbossche 028dc2c
implement any/all reductions
jorisvandenbossche 1750bcb
Merge remote-tracking branch 'upstream/main' into string-dtype-object
jorisvandenbossche 7f4baf7
fix typing
jorisvandenbossche fdf1454
Merge remote-tracking branch 'upstream/main' into string-dtype-object
jorisvandenbossche fe6fce6
Update pandas/core/arrays/string_.py
jorisvandenbossche 70325d4
update todo comment
jorisvandenbossche File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For the NA variants, do we really even need to expose/check against the storage or can we always just check that we have a StringDtype with a pd.NA missing value marker?
The main thing I want to decouple users from is relying heavily on things like
StringDtype(storage="python")
, because it makes it really hard to move them away from our internals.Taking one of the examples we talked about for a possible implementation in 3.0, if we used nanoarrow to back a StringArray without taking on a pyarrow dependency, having a bunch of scattered calls to "python" makes that much harder than it needs to be, without a ton of benefit (?)
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 realize the storage= keyword is documented in PDEP-14 so not surprised to see it here; I just generally am hoping to minimize how often it appears to users in non-developmental / internal contexts
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.
You mean that our asserters (
assert_frame_equal
et al) would consider a column with string dtype backed by pyarrow vs python as equal? (as long as thena_value
is equal)Yes, I also want to ensure that our general goal is that essentially almost no user should have to be explicit about the storage (that's also one of the reasons that I do not want to include the storage in the string alias for the new-to-be-default string dtype).
But, this is about a developer tool. Currently we regard
pd.StringDtype("pyarrow") == pd.StringDtype("python")
as False, and soassert_frame_equal
will fail for that. And in that case, for the developer UX, the assert error message should be clear.Right now, you can get something like:
which is not very helpful ...
The reason for that is because I did not bake the
pd.NA
vsnp.nan
information in the string alias / representation.See also #59342 for an issue about this that was just opened (we should probably continue the main discussion about an informative repr there, but short term I want to include something like the above as a short-term solution until we decide on the best way forward to address the issues in #59342)
FWIW I also added this code change in #59352 (to fix up failing tests on main) but with a comment explaining the issue.
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.
Yea exactly. I'm not sure I 100% feel that way and I see both sides to the argument, but wanted to raise it for discussion
Understood and agreed on all of your other points
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.
For the asserters and how to treat variants of the same dtype, that is a topic we certainly have to discuss more in general as well when expanding this topic to other dtypes (PDEP 13).
Personally, I think there is indeed something to say about treating those dtypes as equal, or at least have an option to toggle how "strict" the dtype check is.