Skip to content

Transform with np.any / np.all and NA in Group Raises #20653

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

Closed
WillAyd opened this issue Apr 11, 2018 · 1 comment · Fixed by #20655
Closed

Transform with np.any / np.all and NA in Group Raises #20653

WillAyd opened this issue Apr 11, 2018 · 1 comment · Fixed by #20655
Labels
Bug Groupby Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Milestone

Comments

@WillAyd
Copy link
Member

WillAyd commented Apr 11, 2018

In [17]: df = pd.DataFrame([['foo', True],                                                          
    ...:                    [np.nan, True],
    ...:                    ['foo', True]], columns=['key', 'val'])

In [13]: df.groupby('key')['val'].transform('any') 
Out[13]: 
0    True
1     NaN
2    True
Name: val, dtype: object

In [14]: df.groupby('key')['val'].transform(np.any)
...
~/clones/pandas/pandas/core/internals.py in set_axis(self, axis, new_labels)
   3280             raise ValueError(
   3281                 'Length mismatch: Expected axis has {old} elements, new '
-> 3282                 'values have {new} elements'.format(old=old_len, new=new_len))
   3283 
   3284         self.axes[axis] = new_labels

ValueError: Length mismatch: Expected axis has 2 elements, new values have 3 elements

I've only seen this value error when using np.any and np.all. Other aggs (at least np.sum, np.min, np.max) seem to work fine

INSTALLED VERSIONS

commit: fa24af9
python: 3.6.4.final.0
python-bits: 64
OS: Darwin
OS-release: 17.5.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.23.0.dev0+738.gfa24af91a.dirty
pytest: 3.4.1
pip: 9.0.1
setuptools: 38.5.1
Cython: 0.27.3
numpy: 1.14.1
scipy: 1.0.0
pyarrow: 0.8.0
xarray: 0.10.0
IPython: 6.2.1
sphinx: 1.7.0
patsy: 0.5.0
dateutil: 2.6.1
pytz: 2018.3
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.4
feather: 0.4.0
matplotlib: 2.1.2
openpyxl: 2.5.0
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.0.2
lxml: 4.1.1
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.2.5
pymysql: 0.8.0
psycopg2: 2.7.4 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: 0.1.3
fastparquet: 0.1.4
pandas_gbq: None
pandas_datareader: None

@gfyoung gfyoung added Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Bug labels Apr 11, 2018
@gfyoung
Copy link
Member

gfyoung commented Apr 11, 2018

That sounds odd! Investigation and PR are welcome!

@jreback jreback added this to the 0.23.0 milestone Apr 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Groupby Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants