-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Add test for #32108 (error with groupby on series with period index) #33105
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
Conversation
daxid
commented
Mar 28, 2020
- closes Series with NAMED period index raise error on groupby index.month (pandas 1.0 specific) #32108
Line 2062:1: E302 expected 2 blank lines, found 1 Line 2063:12: E225 missing whitespace around operator Line 2069:33: E231 missing whitespace after ',' Line 2069:57: E231 missing whitespace after ',' Line 2069:65: E226 missing whitespace around arithmetic operator
##[error]pandas/tests/groupby/test_groupby.py:2062: <- trailing whitespaces found ##[error]./pandas/tests/groupby/test_groupby.py:15:1:F811:redefinition of unused 'Series' from line 11 ##[error]ERROR: /home/runner/work/pandas/pandas/pandas/tests/groupby/test_groupby.py Imports are incorrectly sorted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @daxid !
pandas/tests/groupby/test_groupby.py
Outdated
@@ -2057,3 +2057,15 @@ def test_groups_repr_truncates(max_seq_items, expected): | |||
|
|||
result = df.groupby(np.array(df.a)).groups.__repr__() | |||
assert result == expected | |||
|
|||
|
|||
def test_groupby_period_index(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the issue number here:
def test_groupby_period_index():
# GH 32108
pandas/tests/groupby/test_groupby.py
Outdated
|
||
def test_groupby_period_index(): | ||
periods = 2 | ||
index = period_range(start='2018-01', periods=periods, freq='M') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you haven't run black
, and perhaps not flake8
either. See code standards
I've done the corrections, all tests are passing now, sorry for the delay |
pandas/tests/groupby/test_groupby.py
Outdated
@@ -2057,3 +2057,16 @@ def test_groups_repr_truncates(max_seq_items, expected): | |||
|
|||
result = df.groupby(np.array(df.a)).groups.__repr__() | |||
assert result == expected | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you move this under test_grouper_index_types (same file). ping on green.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function test_grouper_index_types
is in the file pandas/tests/groupby/test_grouping.py
our test is in pandas/tests/groupby/test_groupby.py
, do you want us to move our test to test_grouping.py
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes pls move this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
# GH 32108 | ||
periods = 2 | ||
index = pd.period_range(start="2018-01", periods=periods, freq="M") | ||
periodSerie = pd.Series(range(periods), index=index) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
naming this periodSerie
doesn't conform to PEP8 - sorry for not bringing this up sooner, I thought flake8 would've caught it. seems there's an open issue to add extra plugins though (#20588)
Function and Variable Names
Function names should be lowercase, with words separated by underscores as necessary to improve readability.Variable names follow the same convention as function names.
mixedCase is allowed only in contexts where that's already the prevailing style (e.g. threading.py), to retain backwards compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, I hope it's all good now :)
@daxid thanks for working on this. seems to have been lost in the shuffle. can you merge master to trigger ci. |
done |
can you merge master |
done |
period_serie.index.name = "Month" | ||
result = period_serie.groupby(period_serie.index.month).sum() | ||
|
||
expected = pd.Series(range(0, periods), index=range(1, periods + 1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can construct the Index(...., name=...)
def test_grouper_period_index(self): | ||
# GH 32108 | ||
periods = 2 | ||
index = pd.period_range(start="2018-01", periods=periods, freq="M") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pass name=
@@ -149,6 +149,18 @@ def test_grouper_index_types(self): | |||
df.index = list(reversed(df.index.tolist())) | |||
df.groupby(list("abcde")).apply(lambda x: x) | |||
|
|||
def test_grouper_period_index(self): | |||
# GH 32108 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this to pandas/tests/groupby/test_timegrouper.py
Done once again |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @daxid generally lgtm can you address #33105 (comment)
|
||
expected = pd.Series( | ||
range(0, periods), | ||
index=Index(range(1, periods + 1), name=period_serie.index.name), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe have name as index.name or just be explicit and use name="Month"
Is that version good for you ? |
it appears that #33105 (comment) has not been addressed period_serie -> period_series otherwise lgtm. Thanks @daxid |
I am not sure to understand you request, do you want us to add a |
Pretty sure the request is to rename |
Thanks did now saw the |
thanks @daxid |