Skip to content

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

Merged
merged 12 commits into from
Jun 24, 2020

Conversation

daxid
Copy link
Contributor

@daxid daxid commented Mar 28, 2020

@pep8speaks
Copy link

pep8speaks commented Mar 28, 2020

Hello @daxid! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2020-06-24 20:14:10 UTC

daxid added 2 commits March 28, 2020 21:32
    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.
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @daxid !

@@ -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():
Copy link
Member

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


def test_groupby_period_index():
periods = 2
index = period_range(start='2018-01', periods=periods, freq='M')
Copy link
Member

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

@dbeniamine
Copy link

I've done the corrections, all tests are passing now, sorry for the delay

@jreback jreback added Groupby Period Period data type Testing pandas testing functions or related to the test suite labels Mar 30, 2020
@jreback jreback added this to the 1.1 milestone Mar 30, 2020
@@ -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


Copy link
Contributor

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.

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 ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes pls move this

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)
Copy link
Member

@MarcoGorelli MarcoGorelli Apr 4, 2020

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.

https://www.python.org/dev/peps/pep-0008/

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 :)

@simonjayhawkins
Copy link
Member

@daxid thanks for working on this. seems to have been lost in the shuffle. can you merge master to trigger ci.

@dbeniamine
Copy link

@daxid thanks for working on this. seems to have been lost in the shuffle. can you merge master to trigger ci.

done

@jreback
Copy link
Contributor

jreback commented Jun 14, 2020

can you merge master

@dbeniamine
Copy link

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))
Copy link
Contributor

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")
Copy link
Contributor

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
Copy link
Contributor

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

@dbeniamine
Copy link

Done once again

Copy link
Member

@simonjayhawkins simonjayhawkins left a 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),
Copy link
Member

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"

@dbeniamine
Copy link

Is that version good for you ?

@simonjayhawkins
Copy link
Member

it appears that #33105 (comment) has not been addressed period_serie -> period_series otherwise lgtm. Thanks @daxid

@dbeniamine
Copy link

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 name= parameter in the period_serie construction or do you want us to change the name period_serie to something else, maybe month_serie ?

@MarcoGorelli
Copy link
Member

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 name= parameter in the period_serie construction or do you want us to change the name period_serie to something else, maybe month_serie ?

Pretty sure the request is to rename period_serie to period_series

@dbeniamine
Copy link

Pretty sure the request is to rename period_serie to period_series

Thanks did now saw the s so I wasn't understing this request, should be good now

@jreback jreback merged commit 3f4f564 into pandas-dev:master Jun 24, 2020
@jreback
Copy link
Contributor

jreback commented Jun 24, 2020

thanks @daxid

fangchenli pushed a commit to fangchenli/pandas that referenced this pull request Jun 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Groupby Period Period data type Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Series with NAMED period index raise error on groupby index.month (pandas 1.0 specific)
6 participants