-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Dataclass support #21910
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
Comments
AFAIK is s not guaranteed that you can know that a certain instance is a dataclass. E.g. Classes do not inherit from dataclass. From your example: @dataclass
class SimpleDataObject(object):
field_a: int
field_b: str
x = SimpleDataObject(a=2, b=‘f’) I dont think you could even tell from introspection that |
The That said I'm not sure we should quickly commit to any specific API/support here. For now the the In [18]: from dataclasses import asdict
In [19]: pd.DataFrame([asdict(x) for x in [dataclass_object1, dataclass_object2]])
Out[19]:
field_a field_b
0 1 a
1 2 b |
I compiled a solution where I check the data provided during __init__, in this PR, however, it looks like their testing pipeline is setup to support multiple py-versions. So I may need a bit more time to make this happen. |
Proposal description
Dataclasses were added in Python 3.7.
It would be nice for pandas to support dataclasses. For example could be possible to construct dataframe from by calling
.from_dataclasses
or just.DataFrame(data=dataclass_list)
. There should be also possibility to do.to_dataclasses
.Expected Behaviour
The text was updated successfully, but these errors were encountered: