Skip to content
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

Add __getattr__ override to MicroDataFrame #220

Open
nikhilwoodruff opened this issue Mar 30, 2021 · 3 comments
Open

Add __getattr__ override to MicroDataFrame #220

nikhilwoodruff opened this issue Mar 30, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@nikhilwoodruff
Copy link
Collaborator

This would allow:

df = mdf.MicroDataFrame(dict(first_column=[1, 2, 3]), weights=[2, 2, 1])
df.first_column

Currently, we can only do:

df["first_column"]

We just would need to add a getattr override to MicroDataFrame, call the super function and wrap the results in the same MicroDataFrame configuration that it's called from.

@nikhilwoodruff nikhilwoodruff added the bug Something isn't working label Mar 30, 2021
@hdoupe
Copy link

hdoupe commented Mar 30, 2021

Hey @nikhilwoodruff, I've been passively lurking in the Github notifications for this project and have enjoyed seeing the progress y'all are making!

I did something kinda similar in Tax-Calculator a few months ago if it's helpful: https://github.com/hdoupe/Tax-Calculator/blob/df-based/taxcalc/data.py#L313-L342

Although judging from the work you've done already, you don't need my help haha.

@nikhilwoodruff
Copy link
Collaborator Author

Thanks @hdoupe, that tax-calc example is pretty cool, and interesting that it uses setattr too. Not sure if there's any Pandas uses for setattr we need to cover @MaxGhenis?

@MaxGhenis
Copy link
Collaborator

pandas lets you overwrite an existing value with setattr, but only if the column already exists:

import pandas as pd
df = pd.DataFrame({"x": [1]})
df.x = 2
df

yields:

	x
0	2

Where:

df.y = 2
df

still yields:

	x
0	2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants