PolicyEngine / microdf

Analysis tools for working with survey microdata as DataFrames.
http://pslmodels.github.io/microdf
MIT License
12 stars 10 forks source link

Subsetted MicroDataFrames are not MicroDataFrames #172

Closed MaxGhenis closed 3 years ago

MaxGhenis commented 3 years ago

MRE:

import microdf as mdf
df = mdf.MicroDataFrame({"x": [1, 2, 3]}, weights=[4, 5, 6])
df[df.x > 1].__class__
Out[4]: pandas.core.frame.DataFrame

This means there are no weights:

df[df.x > 1].weights

AttributeError: 'DataFrame' object has no attribute 'weights'

And accordingly, functions over subsetted MicroDataFrames are not weighted (this should be 2 * 5 + 3 * 6 = 28):

In [2]: df[df.x > 1].sum()
Out[2]: 
x    5
nikhilwoodruff commented 3 years ago

Fixed in #169