Skip to content

STYLE loosen inconsistent namespace check #40532

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

Conversation

MarcoGorelli
Copy link
Member

For context, see #40468, where the error which was fixed was arguably a false-positive.

I've loosened the check so that now it only errors / replaces if:

  • you imported an object from somewhere in pandas e.g. from pandas.io.formats import info
  • you also accessed that object as pd. or pandas. (e.g. pd.info or pandas.info)

Before, it just checked whether an object appeared both with and without the pd. prefix, which was too tight a check - sorry about that 😳

I've also added line number and column offset of the inconsistency for ease of checking/fixing

@MarcoGorelli MarcoGorelli added the Code Style Code style, linting, code_checks label Mar 20, 2021
@MarcoGorelli MarcoGorelli force-pushed the loosen-inconsistent-namespace-check branch from c211695 to a5e0d1f Compare March 20, 2021 12:33
Copy link
Member

@dsaxton dsaxton left a comment

Choose a reason for hiding this comment

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

Nice @MarcoGorelli. Was this check still running only for tests? If so maybe it could be extended to ordinary source files too (although it seems that tests are where most of the violations tend to be)?

self.pandas_namespace: MutableMapping[Offset, str] = {}
self.no_namespace: Set[str] = set()
self.pandas_namespace: MutableMapping[OffsetWithNamespace, str] = {}
self.imported_from_pandas: Set[str] = set()
Copy link
Member

Choose a reason for hiding this comment

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

Outside scope of the PR of course, but curious how hard it would be to generalize this to any namespace? Then you could see it being a helpful linting check even outside of pandas.

Copy link
Member Author

@MarcoGorelli MarcoGorelli Mar 20, 2021

Choose a reason for hiding this comment

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

That's a great idea, thanks! Added to my backlog

@MarcoGorelli MarcoGorelli marked this pull request as draft March 20, 2021 17:05
@MarcoGorelli MarcoGorelli marked this pull request as ready for review March 20, 2021 18:03
@jbrockmendel
Copy link
Member

can you merge master; i think the docbuild should be fixed (not sure about the other one)

@jreback jreback added this to the 1.3 milestone Mar 23, 2021
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

lgtm. @jorisvandenbossche if any comments

@jreback
Copy link
Contributor

jreback commented Mar 30, 2021

@MarcoGorelli can you merge master and ping on greenish

@jreback
Copy link
Contributor

jreback commented Apr 2, 2021

@MarcoGorelli if you an merge master once more

@MarcoGorelli
Copy link
Member Author

@jreback sure, done

@jreback jreback merged commit 6bd2640 into pandas-dev:master Apr 2, 2021
@jreback
Copy link
Contributor

jreback commented Apr 2, 2021

thanks @MarcoGorelli

@MarcoGorelli MarcoGorelli deleted the loosen-inconsistent-namespace-check branch April 2, 2021 16:30
vladu pushed a commit to vladu/pandas that referenced this pull request Apr 5, 2021
JulianWgs pushed a commit to JulianWgs/pandas that referenced this pull request Jul 3, 2021
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants