Skip to content

BUG: slicing DataFrameGroupBy to SeriesGroupBy doesn't propagate dropna #35745

Closed
@arw2019

Description

@arw2019
  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


xref #9959, #35444

Slicing a DataFrameGroupBy object to SeriesGroupBy doesn't correctly propagate dropna.

The DataFrameGroupByDataFrameGroupBy case is being handled in #35444. Opening this because as far as I can tell the DataFrameGroupBySeriesGroupBy variant is an independent bug.

Code Sample, a copy-pastable example

In [11]: df = pd.DataFrame({"a": [1], "b": [2], "c": [3]}) 
    ...: gb = df.groupby('a', dropna=False)                                                                                                                                                                       

In [12]: gb.dropna                                                                                                                                                                                                
Out[12]: False

In [13]: gb['b'].dropna                                                                                                                                                                                   
Out[13]: True

Expected Output

I'd like to see:

In [22]: gb.dropna == gb['b'].dropna                                                                                                                                                                              
Out[22]: True

Output of pd.show_versions()

INSTALLED VERSIONS

commit : a3f5c6a
python : 3.8.3.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-42-generic
Version : #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020
machine : x86_64
processor :
byteorder : little
LC_ALL : C.UTF-8
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.2.0.dev0+99.ga3f5c6a5a.dirty
numpy : 1.18.5
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 49.1.0.post20200704
Cython : 0.29.21
pytest : 5.4.3
hypothesis : 5.19.0
sphinx : 3.1.1
blosc : None
feather : None
xlsxwriter : 1.2.9
lxml.etree : 4.5.2
html5lib : 1.1
pymysql : None
psycopg2 : 2.8.5 (dt dec pq3 ext lo64)
jinja2 : 2.11.2
IPython : 7.16.1
pandas_datareader: None
bs4 : 4.9.1
bottleneck : 1.3.2
fsspec : 0.7.4
fastparquet : 0.4.0
gcsfs : 0.6.2
matplotlib : 3.2.2
numexpr : 2.7.1
odfpy : None
openpyxl : 3.0.4
pandas_gbq : None
pyarrow : 0.17.1
pytables : None
pyxlsb : None
s3fs : 0.4.2
scipy : 1.5.0
sqlalchemy : 1.3.18
tables : 3.6.1
tabulate : 0.8.7
xarray : 0.15.1
xlrd : 1.2.0
xlwt : 1.3.0
numba : 0.50.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions