Skip to content

Changed SeriesGroupBy to return Series #445

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 2 commits into from
Nov 25, 2022
Merged

Changed SeriesGroupBy to return Series #445

merged 2 commits into from
Nov 25, 2022

Conversation

ramvikrams
Copy link
Contributor

ascending: bool = ...,
bins=...,
dropna: bool = ...,
) -> Series: ...
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need two overloads?

Copy link
Contributor

Choose a reason for hiding this comment

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

Should not need two overloads when both return Series.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the file thanks

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually there should be two overloads here, and I realized this after merging. @ramvikrams can you open a new PR with this:

    @overload
    def value_counts(
        self,
        normalize: Literal[False] = ...,
        sort: bool = ...,
        ascending: bool = ...,
        bins=...,
        dropna: bool = ...,
    ) -> Series[int]: ...
    @overload
    def value_counts(
        self,
        normalize: Literal[True]
        sort: bool = ...,
        ascending: bool = ...,
        bins=...,
        dropna: bool = ...,
    ) -> Series[float]: ...

The changes from what you initially had are not doing = ... for normalize in the second overload, and adding the subtype as the return type of the two overloads.

In the test, don't do c: pd.Series =, and modify the test to check that it returns Series[int], and then add a test with normalize=True and check thtat it returns Series[float]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes sir will do that

@@ -1942,3 +1942,14 @@ def series_added_in_astype() -> None:
# GH410
df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
check(assert_type(df.astype(df.dtypes), pd.DataFrame), pd.DataFrame)


def test_SeriesGroupBy_and_value_conts() -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a typo here. And why is it in frame tests? There are no similar tests to put it with?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, please use standard python function naming, e.g., test_series_groupby_and_value_counts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes sir

Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

thanks @ramvikrams

IN the future, please name your branches related to what you are fixing

@Dr-Irv Dr-Irv merged commit e0f0fe1 into pandas-dev:main Nov 25, 2022
@ramvikrams
Copy link
Contributor Author

ramvikrams commented Nov 25, 2022

thanks @ramvikrams

IN the future, please name your branches related to what you are fixing

ok sir will surely do that
thank you @Dr-Irv

@MarcoGorelli
Copy link
Member

But should copy overloads from DataFrameGroupBy for value_counts() to handle normalize argument correctly.

sorry @Dr-Irv , I'm confused - shouldn't overloads have been added to return Series[float] if normalize=True and Series[int] otherwise?

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Nov 25, 2022

But should copy overloads from DataFrameGroupBy for value_counts() to handle normalize argument correctly.

sorry @Dr-Irv , I'm confused - shouldn't overloads have been added to return Series[float] if normalize=True and Series[int] otherwise?

Yes, and I think I was typing the same message while you were typing yours!

Dr-Irv pushed a commit that referenced this pull request Nov 29, 2022
* Follow up PR for changes requested in #445

* updated the test_frame.py by changing the assert-type and adding the second check type
@refack refack mentioned this pull request Sep 8, 2024
2 tasks
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 this pull request may close these issues.

SeriesGroupBy.value_counts() should return Series not DataFrame
5 participants