BUG: GroupBy.first does not skip missing values in string-valued columns #38286
Labels
Groupby
Missing-data
np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Regression
Functionality that used to work in a prior pandas version
Milestone
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.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
Problem description
One utility of the GroupBy.first() function is its coalescing behavior--it skips missing values within groups. This behavior does not seem to happen when a column has string values, which creates two problems: 1) type-dependent behavior of an otherwise generic method, and 2) I'm not able to find a workaround to get the behavior I'd like (returning the first non-missing string in a group.
Expected Output
I would expect the output of the second example above to be "foo", not None. If the behavior above is the expected behavior of Pandas, then please provide the correct code to use in order to extract the first non-missing string in a groupby column.
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : 67a3d42
python : 3.8.5.final.0
python-bits : 64
OS : Darwin
OS-release : 19.6.0
Version : Darwin Kernel Version 19.6.0: Thu Oct 29 22:56:45 PDT 2020; root:xnu-6153.141.2.2~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.1.4
numpy : 1.19.4
pytz : 2020.4
dateutil : 2.8.1
pip : 20.2.3
setuptools : 50.2.0
Cython : None
pytest : 6.1.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.19.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.2
numexpr : None
odfpy : None
openpyxl : 3.0.5
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: