Skip to content

Extend check for inconsistent pandas namespace usage #38093

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 Nov 26, 2020 · 4 comments
Closed

Extend check for inconsistent pandas namespace usage #38093

MarcoGorelli opened this issue Nov 26, 2020 · 4 comments
Assignees
Labels
Code Style Code style, linting, code_checks good first issue

Comments

@MarcoGorelli
Copy link
Member

MarcoGorelli commented Nov 26, 2020

xref #38076 - it can probably be extended beyond checking for classes.

Steps would be:

  1. change PATTERN in scripts/check_for_inconsistent_pandas_namespace.py to
PATTERN = r"""
    (
        (?<!pd\.)(?<!\w)    # check class_name doesn't start with pd. or character
        (\w+)\(        # match DataFrame but not pd.DataFrame or tm.makeDataFrame
        .*                  # match anything
        pd\.\2\(            # only match e.g. pd.DataFrame
    )|
    (
        pd\.(\w+)\(    # only match e.g. pd.DataFrame
        .*                  # match anything
        (?<!pd\.)(?<!\w)    # check class_name doesn't start with pd. or character
        \4\(                # match DataFrame but not pd.DataFrame or tm.makeDataFrame
    )
    """

and save.

  1. run pre-commit run inconsistent-namespace-usage --all-files, check the error messages, and fix them up

Here are the files which need fixing:

- [ ] pandas/tests/arrays/floating/test_to_numpy
- [ ] pandas/tests/extension/decimal/test_decimal
- [ ] pandas/tests/io/test_sql
- [ ] pandas/tests/series/test_constructors
- [ ] pandas/tests/arrays/test_datetimes
- [ ] pandas/tests/frame/test_stack_unstack
- [ ] pandas/tests/arrays/boolean/test_comparison
- [ ] pandas/tests/internals/test_internals
- [ ] pandas/tests/arrays/masked/test_arrow_compat
- [ ] pandas/tests/reshape/merge/test_multi
- [ ] pandas/tests/indexing/test_datetime
- [ ] pandas/tests/scalar/timestamp/test_unary_ops

This can probably all be one in a single PR.

  1. To check you've fixed up a file completely, running
pre-commit run inconsistent-namespace-usage --files <file.py>

should return "PASSED".

@kevinetienne
Copy link

take

@MarcoGorelli
Copy link
Member Author

Hi @kevinetienne - are you still working on this?

@kevinetienne
Copy link

Yes, I have work I need to push, which I'll do today. Thank you.

@MarcoGorelli
Copy link
Member Author

In the end, using a regex was too complicated / brittle for this, so in #39690 I've gone ahead and done it using ast.parse. It could still be expanded to other parts of the codebase, but I'll leave that for a separate issue

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
Projects
None yet
Development

No branches or pull requests

2 participants