Skip to content

STYLE, TYP frame-or-series-union check no longer relevant #40876

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
MarcoGorelli opened this issue Apr 11, 2021 · 12 comments · Fixed by #41955
Closed

STYLE, TYP frame-or-series-union check no longer relevant #40876

MarcoGorelli opened this issue Apr 11, 2021 · 12 comments · Fixed by #41955
Assignees
Labels
Code Style Code style, linting, code_checks good first issue Typing type annotations, mypy/pyright type checking
Milestone

Comments

@MarcoGorelli
Copy link
Member

MarcoGorelli commented Apr 11, 2021

This check is no longer relevant:

- id: frame-or-series-union
name: Check for use of Union[Series, DataFrame] instead of FrameOrSeriesUnion alias
entry: Union\[.*(Series,.*DataFrame|DataFrame,.*Series).*\]
language: pygrep
types: [python]
exclude: ^pandas/_typing\.py$

Since using PEP604 rewrites, this would be written as

x: Series | DataFrame

anyway.

x: FrameOrSeriesUnion

is actually just as long as the above, and arguably less explicit.


@simonjayhawkins thoughts on replacing all the FrameOrSeriesUnion occurrences, removing the alias, and removing the above check?

@MarcoGorelli MarcoGorelli added Code Style Code style, linting, code_checks Typing type annotations, mypy/pyright type checking labels Apr 11, 2021
@simonjayhawkins
Copy link
Member

+1

@mohansaimandalapu
Copy link

Hi MarcoGorelli

I would like to take up this issue, this is my first open source PR, I couldn't understand the issue completely. It would be great if you can elucidate it. Thank you

@MarcoGorelli
Copy link
Member Author

Sure. At the moment, we alias DataFrame | Series as FrameOrSeriesUnion, the issue is simply to remove the alias. So:

  1. remove this check:

    - id: frame-or-series-union
    name: Check for use of Union[Series, DataFrame] instead of FrameOrSeriesUnion alias
    entry: Union\[.*(Series,.*DataFrame|DataFrame,.*Series).*\]
    language: pygrep
    types: [python]
    exclude: ^pandas/_typing\.py$

  2. remove this alias:

    pandas/pandas/_typing.py

    Lines 97 to 101 in 895f0b4

    # FrameOrSeriesUnion means either a DataFrame or a Series. E.g.
    # `def func(a: FrameOrSeriesUnion) -> FrameOrSeriesUnion: ...` means that if a Series
    # is passed in, either a Series or DataFrame is returned, and if a DataFrame is passed
    # in, either a DataFrame or a Series is returned.
    FrameOrSeriesUnion = Union["DataFrame", "Series"]

  3. Anywhere in the codebase which uses this alias, replace it with DataFrame | Series

If anything is unclear, please do ask :)

@Swanand01
Copy link
Contributor

Hello @MarcoGorelli, first time contributor here. I would like to take up this issue.
If I understand correctly, the check and alias have to be removed, and all instances of FrameOrSeriesUnion in the codebase have to be replaced with Series | DataFrame.
Thank you.

@joonlim9
Copy link

take

@MarcoGorelli
Copy link
Member Author

I think @mohansaimandalapu is already working on this

@joonlim9
Copy link

I think @mohansaimandalapu is already working on this
I thought multiple contributors on a single issue is allowed, my bad.

@MarcoGorelli
Copy link
Member Author

MarcoGorelli commented May 18, 2021

I think @mohansaimandalapu is already working on this
I thought multiple contributors on a single issue is allowed, my bad.

Hey @joonlim9 - it doesn't look like they're working on it

Anyone is free to work on this now

@Anupam-USP
Copy link
Contributor

PR is merged so is this issue closed? @MarcoGorelli

@simonjayhawkins
Copy link
Member

PR is merged so is this issue closed? @MarcoGorelli

#41546 is the PR to address this issue and that is not merged.

@Anupam-USP
Copy link
Contributor

Can I take it?

@MarcoGorelli
Copy link
Member Author

Can I take it?

If the author of #41546 doesn't update in, say, another week, then yeah, sure - let's leave them a couple weeks to get back to us at least

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Style Code style, linting, code_checks good first issue Typing type annotations, mypy/pyright type checking
Projects
None yet
6 participants