-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: Add support for dataclasses in the DataFrame constructor #27999
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
Conversation
- added a is_dataclass_inst function to detect dataclasses
Hello @asosnovsky! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2020-03-14 23:03:57 UTC |
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.
Needs a release note (1.0.rst).
A few edge cases we should have tests for
- A mixture of dataclass types (probably takes the union of all the columns?)
- A mixture of dataclass and non-dataclass (this probably raises. Can we ensure that the error message is reasonable)
using make_dataclass in tests
Co-Authored-By: Tom Augspurger <[email protected]>
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.
Added some comments on the doc addition!
Co-Authored-By: Joris Van den Bossche <[email protected]>
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.
looks pretty good, some changes, ping on green.
@@ -430,6 +430,12 @@ def _get_axes(N, K, index, columns): | |||
return index, columns | |||
|
|||
|
|||
def _dataclasses_to_dicts(data): |
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.
can you try to type things (you can add in a TYPE_CHECKING block if need be)
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.
ok
- renamed _dataclasses_to_dicts to dataclasses_to_dicts - added docs to dataclasses_to_dicts
Hi @asosnovsky - sorry to chase you up, just wanted to ask whether you're still working on this :) |
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.
looks good. some minor versionadded docs need updating. pls merge master and ping on green.
Hi @asosnovsky , is this active? I'm hesitant to close this as stale as it looks like it's almost done, but we haven't heard from you in over 2 months |
Co-Authored-By: William Ayd <[email protected]>
this looks fine, but needs a rebase if someone wants to merge master. ping on green. |
@jreback green |
thanks @asosnovsky |
Thanks @asosnovsky Very nice. a few comments to follow-up.
|
Not sure if it makes sense to add a "to_dataclasses" method. Would you have to create a dataclass on the fly or feed in one? Not sure about series either. But if we were to do that, don't series need to have a single dtype? What happens to a dataclass with a mixed bag of types ? |
I think this feature is quite cool and worth mentioning here: |
hmm this originally did have a whats new note ; must have gotten lost would take a patch to add one |
@asosnovsky please do that. I'm not a native speaker and I think it'll be easier for you to describe the change :) |
Added support for data-classes when used in the construction of a new dataframe.
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
Simply put, added support to use dataclasses in the following way: