-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: parse categoricals in read_csv #13406
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
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
286d907
ENH: parse categoricals in read_csv
chris-b1 cfa0ce4
clean up dtype checking, add function specialization
chris-b1 849a112
fix some dtype checking
chris-b1 4e0722d
undo type inference add docs and asv
chris-b1 2490949
fix hash table ordering, null categories
chris-b1 1254768
doc fixups; addl tests
chris-b1 da5c5b5
flake8 fix
chris-b1 0f0dba6
wip
chris-b1 1f6093a
rebase
chris-b1 75ed6ba
doc fixups
chris-b1 c78f39f
rebase fixup
chris-b1 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
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.
this is not idiomatic, we don't assign directly to
.categories
, instead use.set_categories
I could see adding a
.apply_categories
accessor, so this would become:df['A'] = df['A'].cat.apply_categories(pd.to_numeric)
which could do the apply-set-with-rename idiomThere 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.
actually on 2nd thought, this is ok. assigning directly to
cat.categories
is fineThere 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.
cc @jorisvandenbossche
cc @JanSchulz
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.
IMO assigning to categories is ok, we even have it in the docs: https://github.com/pydata/pandas/blob/master/pandas/core/categorical.py#L1857
Code is here and checks for same length as old cats: https://github.com/pydata/pandas/blob/master/pandas/core/categorical.py#L546-L570
set_categories
(source) was designed to do more:-> IMO assigning is better and
set_categories
should be avoided until you really have a performance bottleneck due to multiple calls to change the categories...