This warning could potentially prevent bugs, so I'm pretty keen on putting in the effort to enable it.

Many people can work on this one together. To work on it, please: 1. choose 2-3 files 2. make sure you have pylint version 2.15.5 installed (pip install pylint==2.15.5) - check this is the same as the number in the .pre-commit-config.yaml file 3. for each file, run pylint --disable=all --enable=redefined-outer-name <file> 4. fix up the file until it passes 5. stage, commit, push, open pull request

For example, suppose you choose the file pandas/io/json/_table_schema.py. Running pylint on it, you get:

$ pylint --disable=all --enable=redefined-outer-name pandas/io/json/_table_schema.py
************* Module pandas.io.json._table_schema
pandas/io/json/_table_schema.py:314:23: W0621: Redefining name 'json' from outer scope (line 15) (redefined-outer-name)

-----------------------------------
Your code has been rated at 9.92/10

If we look at that file, we see that there's a function

def parse_table_schema(json, precise_float):

which takes json as an argument, but the file also has

from pandas._libs import json

at the top.

The simplest fix is probably to just modify the import to be

from pandas._libs.json import loads

and then to remove

https://github.com/pandas-dev/pandas/blob/f9ff3796329e4bedb4a5477739f5eb8d2e40761d/pandas/io/json/_table_schema.py#L44

as loads is the only function used from pandas._libs.json.


Other notes: 1. multiple people can work on this issue at the same time, please don't comment 'take' 2. please choose no more than 3 files to work on in the same PR. Comment which files you'd like to take so we don't duplicate work

It's probably worth running pylint on a directory first to see what files need working on, e.g.

pylint --disable=all --enable=redefined-outer-name pandas/io/

Files that still need fixing:

  • pandas/_version.py
  • pandas/conftest.py
  • pandas/core/generic.py
  • pandas/core/internals/concat.py
  • pandas/core/reshape/merge.py
  • pandas/core/tools/datetimes.py
  • pandas/io/formats/format.py
  • pandas/io/formats/style.py
  • pandas/io/json/_json.py
  • pandas/io/xml.py
  • pandas/util/_decorators.py
  • pandas/util/_doctools.py

Let's ignore test files for now

Comment From: grtcoder

Hey, I would like to work on this

Comment From: MarcoGorelli

go ahead - as mentioned in the issue:

please choose no more than 3 files to work on in the same PR. Comment which files you'd like to take so we don't duplicate work

Comment From: ramvikrams

I'll take pandas\core\generic.py

Comment From: grtcoder

I'll take

  1. pandas/core/arrays/datetimelike.py
  2. pandas/core/base.py
  3. pandas/core/computation/pytables.py

Comment From: giridhrubajyoti2002

I'll take pandas/core/internals/concat.py, pandas/core/reshape/merge.py, pandas/io/json/_json.py.

Comment From: bhaveshrp

I'll take

  1. pandas\core\frame.py
  2. pandas\core\dtypes\inference.py

Comment From: alphacrack

I'll take: 1. pandas/core/dtypes/cast.py 2. pandas/core/dtypes/dtypes.py 3. pandas/core/indexes/base.py

Comment From: aditya-anulekh

Added a pull request fixing the following files

  • pandas/core/indexes/datetimes.py
  • pandas/io/formats/xml.py
  • pandas/io/json/_table_schema.py

Comment From: nandinimalik16

I will take

  1. pandas/_version.py
  2. pandas/conftest.py
  3. pandas/io/formats/format.py

Comment From: isaac-chung

I'll take:

  1. pandas/plotting/_matplotlib/converter.py
  2. pandas/plotting/_matplotlib/core.py
  3. pandas/plotting/_matplotlib/tools.py

Comment From: seanjedi

Hi, I'd like to work on: 1. pandas/io/formats/style.py 2. pandas/io/json/_json.py 3. pandas/io/xml.py

Comment From: zemnly

Are there any files which haven't been taken so I can work on them?

Comment From: MarcoGorelli

Yeah there's still some, I've updated the issue with an up-to-date list

Note that https://github.com/pandas-dev/pandas/pull/49668/files is already tackling some, but the rest should be up for grabs

Thanks all for your help with this one 🙏

Comment From: zemnly

Thanks, I'd like to take : 1. pandas/core/algorithms.py 2. pandas/core/generic.py 3. pandas/core/tools/datetimes.py

Comment From: calhockemeyer

I will take: pandas/core/resample.py. I think that's the only file that hasn't been taken

Comment From: bang128

Can I also contribute to pandas/core/algorithms.py?

Comment From: ramvikrams

Can I also contribute to pandas/core/algorithms.py?

Yes you can i'll leave that file

Comment From: bang128

Can I also contribute to pandas/core/algorithms.py?

Yes you can i'll leave that file

Thank you so much!

Comment From: zmwaris1

Hey, I'd like to work on these files if anyone else is not already working on it: pandas/core/internals/concat.py pandas/core/reshape/merge.py pandas/io/json/_json.py

Thanks.

Comment From: MarcoGorelli

@zmwaris1 please do - I've updated the list of files which still need doing

Comment From: seanjedi

@zmwaris1 I apologize for the lateness, been having a hectic past two days. I saw your post above, and I wanted you to know that I have been working on pandas/io/json/_json.py on my fork recently here: https://github.com/seanjedi/pandas/tree/seanjedi-49724_pylint's_redefined_outer_name I just wanted you to know so that we don't duplicate work effort. Feel free to take a look at it and let me know if I made a mistake or if you have any suggestions on making it better.

Comment From: wchung42

Hi, are there any files that still needs to be worked on?

Comment From: MarcoGorelli

yup, check the issue description

Comment From: JasmandeepKaur

Hi, I'll be working on these files:

pandas/util/_decorators.py
pandas/util/_doctools.py
pandas/util/_test_decorators.py

Comment From: MarcoGorelli

let's leave out pandas/util/_test_decorators.py, but the other two are fine

Comment From: JasmandeepKaur

let's leave out pandas/util/_test_decorators.py, but the other two are fine

Will do.

Comment From: angularOcean

Cross referencing the files that need fixing list with what people have commented on taking it, it looks like everything has/is being handled, is there any other files that need working on?

Comment From: MarcoGorelli

if people have commented but they haven't opened a PR, then feel free to take over

Comment From: angularOcean

Okay it doesn't look like a PR has been opened for pandas/core/tools/datetimes.py or pandas/io/formats/format.py so I will try taking on those two.

Comment From: MarcoGorelli

We're almost done, there's just:

  • pandas/io/formats/format.py
  • pandas/core/generic.py

left

If anyone wants to take them, and then (in the same PR) remove these lines from .pre-commit-config.yaml

https://github.com/pandas-dev/pandas/blob/0429b648709de4af526c8a65313b60a8f7419f1d/.pre-commit-config.yaml#L81-L83

, then we can close the issue

Comment From: Thextan

I will make changes to pandas/core/generic.py and pandas/.pre-commit-config.yaml. This is my first time contributing and I am not very familiar with git so, please help me out if I am doing anything wrong.

Comment From: angularOcean

@Thextan I think we need to fix both format.py and generic.py before we can remove the lines from .pre-commit-config.yaml

Comment From: Thextan

@angularOcean when I ran my check it looked like someone had already fixed io/formats/format.py. I could be mistaken about that. And my changes are not passing the checks, so I may not even be ready for this simple beginner task.

Also, I didn't think the changes to .pre-commit-config.yaml was related to the refactoring for redefine-outer-name.

Comment From: MarcoGorelli

I'll take a look tomorrow, but if you search for the pandas contributing guide you'll find instructions for how to run the precommit checks

Comment From: Thextan

Please feel free to pick up the changes to core/generic.py, io/formats/format.py (if it still needs work), and .pre-commit-config.yaml. I am reading through the contributing guide to make sure I am doing things correctly.

Comment From: MarcoGorelli

@Thextan not sure what you mean, sorry - your PR has been reviewed, do you plan to address the review? If not, no worries, that's fine, but please close the PR so others can work on it

Comment From: MarieKMiko

If there are still changes to be made to pandas/io/formats/format.py or pandas/core/generic.py, I'm happy to take these on

Comment From: MarcoGorelli

Yup, they're still open, if you wanted to submit a PR that'd be great, feel free to reach out (here or on the slack) if anything trips you up

Comment From: antocommi

i'll take pandas/core/generic.py

Comment From: bang128

Have anyone taken pandas/io/formats/format.py yet? If not, can I take it?

Comment From: MarcoGorelli

only pandas/core/generic.py is left, if anyone wants to finish off this issue - doesn't look like there's any PR open

Comment From: bang128

I can take it if no one is working on it

Comment From: MarcoGorelli

go ahead thanks

Comment From: MarcoGorelli

Looks like we forgot to remove this line

https://github.com/pandas-dev/pandas/blob/a955989e033a288a659c4eca46490e7c26aaf93a/.pre-commit-config.yaml#L97

anyone feel like opening a PR to remove it?

Comment From: ramvikrams

pandas/.pre-commit-config.yaml

Done