Skip to content

Conversation

@MarieKMiko
Copy link
Contributor

Fixed redefined-outer-name issue in:

  • pandas/io/formats/format.py

redefined-outer-name t issues raised for:

  • justify function (import from pandas.io.formats.printing)

  • decimal (changed to from decimal import Decimal)

  • is_dates_only parameter conflict with function name

  • updated get_format_datetime64 function with renamed parameter

  • passed related tests in pytest pandas

  • running: pylint --disable=all --enable=redefined-outer-name pandas/io/
    -- > Results in 10.00/10 rating

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

Thanks @MarieKMiko for working on this! Could you also do

I've left a couple of comments - could you also remove file names you've fixed from

|^pandas/core/tools/datetimes\.py
|^pandas/io/formats/format\.py
|^pandas/core/generic\.py

please?


def get_format_datetime64(
is_dates_only: bool, nat_rep: str = "NaT", date_format: str | None = None
is_dates_only_result: bool, nat_rep: str = "NaT", date_format: str | None = None
Copy link
Member

Choose a reason for hiding this comment

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

ideally, let's not rename function arguments

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed this is not ideal- not sure how to account for the issue that is_dates_only is both a function name and an argument in a different function, which seems to be what's causing the issue. Would it be better to rename the function rather than then argument?

Copy link
Member

Choose a reason for hiding this comment

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

ah, I see what you mean, thanks. gosh, that's dirty 😄 taking a look

Copy link
Member

@MarcoGorelli MarcoGorelli Nov 28, 2022

Choose a reason for hiding this comment

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

The function is_dates_only is only used within this file - how about we just rename it to _is_dates_only, and then this argument can stay as it is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that could work - let me double check because there is another function somewhere called _is_dates_only but it may be in a different file

Copy link
Member

Choose a reason for hiding this comment

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

The function is_dates_only is only used within this file

sorry I was wrong, it's used inside that other function in fact

Copy link
Member

@MarcoGorelli MarcoGorelli Nov 28, 2022

Choose a reason for hiding this comment

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

In

def non_reducing_slice(slice_: Subset):

the argument slice is called slice_ to avoid shadowing the builtin slice - shall we do the same here and rename to is_dates_only_?

If you then remove format.py from

|^pandas/io/formats/format\.py

file, the rest looks good 👍

EDIT: in fact, looks like |^pandas/core/tools/datetimes\.py can also already be removed from the pre-commit-config file


def get_format_datetime64(
is_dates_only: bool, nat_rep: str = "NaT", date_format: str | None = None
is_dates_only_result: bool, nat_rep: str = "NaT", date_format: str | None = None
Copy link
Member

@MarcoGorelli MarcoGorelli Nov 28, 2022

Choose a reason for hiding this comment

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

In

def non_reducing_slice(slice_: Subset):

the argument slice is called slice_ to avoid shadowing the builtin slice - shall we do the same here and rename to is_dates_only_?

If you then remove format.py from

|^pandas/io/formats/format\.py

file, the rest looks good 👍

EDIT: in fact, looks like |^pandas/core/tools/datetimes\.py can also already be removed from the pre-commit-config file

@mroeschke mroeschke added the Code Style Code style, linting, code_checks label Nov 28, 2022


def is_dates_only(values: np.ndarray | DatetimeArray | Index | DatetimeIndex) -> bool:
def is_dates_only_(values: np.ndarray | DatetimeArray | Index | DatetimeIndex) -> bool:
Copy link
Member

@MarcoGorelli MarcoGorelli Nov 29, 2022

Choose a reason for hiding this comment

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

ah sorry, I meant to rename the argument get_format_datetime64 (else this function will need renaming in the other file where it's used, i.e.

from pandas.io.formats.format import is_dates_only
)

so, this function would stay as is_dates_only, and

def get_format_datetime64(
is_dates_only: bool, nat_rep: str = "NaT", date_format: str | None = None
) -> Callable:

would change to

def get_format_datetime64( is_dates_only_: bool, nat_rep: str = "NaT", date_format: str | None = None ) -> Callable: 
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh- got it- let me just swap that around

@MarcoGorelli MarcoGorelli added this to the 2.0 milestone Nov 29, 2022
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

Nice! This is probably fine, if you address #49937 (review) as well then this is probably good to go

removed format and datetimes files
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

Looks good to me pending green, well done!

@mroeschke mroeschke merged commit c3a257c into pandas-dev:main Nov 29, 2022
@mroeschke
Copy link
Member

Thanks @MarieKMiko

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

3 participants