Imports should typically be placed at the top of files. Sometimes, imports are placed inside functions to: - avoid circular imports - avoid ImportError if it's an optional dependency

Standard library imports should really always be at the top of files.

Noticed in https://github.com/pandas-dev/pandas/pull/49645 that this is often not the case

I've made a script to automate detecting when this is the case. So the task is:

git checkout -b standard-library-imports main
git pull git@github.com:MarcoGorelli/pandas.git standard-library-imports
git reset --hard FETCH_HEAD
pre-commit run stdlib-imports --all-files

Then, fixup any errors that are reported. Finally, stage your changes, commit them, push them to your fork, and open a pull request

Feel free to reach out if you into any issues along the way

If any wants to take this, it would be a nice and welcome clean up!


EDIT: after going through a PR, I'm not sure it's worth introducing a check for this - but we can still take some of the cleanups it found

Comment From: mroeschke

Noting in the past that some stdlib imports were deferred (i.e. not at the top level) to help import time (not sure if this is still the case)

https://github.com/pandas-dev/pandas/blob/e41b6d7827720df90a51ff05caa689333d7e02af/pandas/io/common.py#L259-L266

Comment From: MarcoGorelli

Ah thanks! Can probably just respect the blocklist

https://github.com/pandas-dev/pandas/blob/bcb8346e8106be4267ec77dfc603d0d77a3fda81/ci/code_checks.sh#L48-L50

EDIT: done

Comment From: grtcoder

Hey, I would like to work on this.

Comment From: MarcoGorelli

sure go ahead

Comment From: zemnly

Hi, can I take this ?

Comment From: MarcoGorelli

looks like @grtcoder is already working on it

Comment From: natmokval

Hi @grtcoder. Do you mind if I will work on this issue as well?

Comment From: MarcoGorelli

feel free to go ahead, doesn't look like it's being worked on

Comment From: Thextan

@natmokval I am starting on this one. I will start with the files under pandas/core/ and pandas/io

Comment From: Thextan

Finished all files except pandas/tests/*. I will work on those next.

Comment From: seanjedi

Is there anything for this issue that I can work on?

Comment From: Thextan

Sean,

I have just about finished this one. I am working on the last 3 files now.

Sent with Proton Mail secure email.

------- Original Message ------- On Thursday, December 1st, 2022 at 5:35 PM, Sean Patrick Malloy @.***> wrote:

Is there anything for this issue that I can work on?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

Comment From: seanjedi

Alright, thanks for letting me know!