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

disable 'str' for 'SeriesGroupBy', disable 'DataFrame' for 'GroupBy' #1095

Closed
itholic opened this issue Dec 3, 2019 · 1 comment · Fixed by #1097
Closed

disable 'str' for 'SeriesGroupBy', disable 'DataFrame' for 'GroupBy' #1095

itholic opened this issue Dec 3, 2019 · 1 comment · Fixed by #1097

Comments

@itholic
Copy link
Contributor

itholic commented Dec 3, 2019

as commented #1050 (comment) ,

we're gonna block generating SeriesGroupby by its column name to follow the behavior of pandas.

>>> import pandas as pd
>>> pser = pd.Series([1, 2, 3, 4, 5], name='x')
>>> pser.groupby(pser.name).head(2)
Traceback (most recent call last):
...
KeyError: 'x'

i think it's better to fix this in separated PR with a separated Issue to make it more clarify and add related tests for existing functions.

+

and also by should not allowed as type of DataFrame like below.

>>> pdf = pd.DataFrame({'a': [1, 2, 6, 4, 4, 6, 4, 3, 7],
...                             'b': [4, 2, 7, 3, 3, 1, 1, 1, 2],
...                             'c': [4, 2, 7, 3, None, 1, 1, 1, 2],
...                             'd': list('abcdefght')},
...                            index=[0, 1, 3, 5, 6, 8, 9, 9, 9])
>>> pdf.groupby(pdf)
Traceback (most recent call last):
...
ValueError: Grouper for '<class 'pandas.core.frame.DataFrame'>' not 1-dimensional

>>> pdf.a.groupby(pdf)
Traceback (most recent call last):
...
ValueError: Grouper for '<class 'pandas.core.frame.DataFrame'>' not 1-dimensional
@itholic
Copy link
Contributor Author

itholic commented Dec 3, 2019

I'm working on this.

@itholic itholic changed the title Block generating SeriesGroupBy by its name. disable 'str' for 'SeriesGroupBy', disable 'DataFrame' for 'GroupBy' Dec 3, 2019
HyukjinKwon pushed a commit that referenced this issue Dec 10, 2019
…1097)

Resolve #1095 

```python
>>> kser = ks.Series([1, 2, 3, 4, 5], name='x')
>>> kser.groupby('x').head(2)
Traceback (most recent call last):
...
KeyError: ('x',)
```
```python
>>> pdf = pd.DataFrame({'a': [1, 2, 6, 4, 4, 6, 4, 3, 7],
...                             'b': [4, 2, 7, 3, 3, 1, 1, 1, 2],
...                             'c': [4, 2, 7, 3, None, 1, 1, 1, 2],
...                             'd': list('abcdefght')},
...                            index=[0, 1, 3, 5, 6, 8, 9, 9, 9])
>>> pdf.groupby(pdf)
Traceback (most recent call last):
...
ValueError: Grouper for '<class 'pandas.core.frame.DataFrame'>' not 1-dimensional

>>> pdf.a.groupby(pdf)
Traceback (most recent call last):
...
ValueError: Grouper for '<class 'pandas.core.frame.DataFrame'>' not 1-dimensional
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant