-
-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Handling conversion of empty categorical with dtype_backend='pyarrow' #59935
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
Closed
veljanin
wants to merge
13
commits into
pandas-dev:main
from
veljanin:fixing_pyarrow_conversion_of_empty_categorical
Closed
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e6ef750
Handling the case where converting empty categorical to 'pyarrow' dty…
veljanin c005850
Merge branch 'main' into fixing_pyarrow_conversion_of_empty_categorical
veljanin 5ce426d
Merge branch 'main' into fixing_pyarrow_conversion_of_empty_categorical
veljanin 94769a1
additional revisions
veljanin 8e879da
removing the change for input_array...
veljanin a5b3882
reverting newline in Series.convert_dtypes and precising respective d…
veljanin c1ed1f0
resolved conflicts and updated main with latest changes
veljanin 6747736
Merge branch 'main' into fixing_pyarrow_conversion_of_empty_categorical
veljanin 82cecd1
adding tm.skip_if_no decorator to tests per feedback
veljanin ae0a148
Merge remote-tracking branch 'origin/fixing_pyarrow_conversion_of_emp…
veljanin c0d8178
Merge remote-tracking branch 'upstream/main' into fixing_pyarrow_conv…
veljanin 902601f
revised testing to resolve CI errors v2
veljanin 482080d
Resolve merge conflicts for code_checks docstrings...
veljanin 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
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -297,3 +297,21 @@ def test_convert_dtypes_pyarrow_null(self): | |||||||
result = ser.convert_dtypes(dtype_backend="pyarrow") | ||||||||
expected = pd.Series([None, None], dtype=pd.ArrowDtype(pa.null())) | ||||||||
tm.assert_series_equal(result, expected) | ||||||||
|
||||||||
def test_convert_empty_categorical_to_pyarrow(self): | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
# GH#59934 | ||||||||
ser1 = pd.Series(pd.Categorical([None] * 5)) | ||||||||
converted1 = ser1.convert_dtypes(dtype_backend="pyarrow") | ||||||||
expected = ser1 | ||||||||
|
||||||||
tm.assert_series_equal(converted1, expected) | ||||||||
assert converted1.dtype == "category", "Series dtype is not 'category'" | ||||||||
assert converted1.cat.categories.empty, "Series categories are not empty" | ||||||||
Comment on lines
+310
to
+311
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar, can remove. |
||||||||
|
||||||||
ser2 = pd.Series(pd.Categorical([None] * 5, categories=["S1", "S2"])) | ||||||||
converted2 = ser2.convert_dtypes(dtype_backend="pyarrow") | ||||||||
assert converted2.cat.categories.__contains__( | ||||||||
"S1" | ||||||||
) and converted2.cat.categories.__contains__( | ||||||||
"S2" | ||||||||
), "Categories in ser2 doesn't contain adequate categories" |
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.
Uh oh!
There was an error while loading. Please reload this page.