Skip to content

STYLE #49656: fixed redefined-outer-name linting issue to format.py #49937

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
merged 11 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ repos:
|^pandas/util/_test_decorators\.py # keep excluded
|^pandas/_version\.py # keep excluded
|^pandas/conftest\.py # keep excluded
|^pandas/core/tools/datetimes\.py
|^pandas/io/formats/format\.py
|^pandas/core/generic\.py
args: [--disable=all, --enable=redefined-outer-name]
stages: [manual]
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def _is_comparable_dtype(self, dtype: DtypeObj) -> bool:
def _formatter_func(self):
from pandas.io.formats.format import get_format_datetime64

formatter = get_format_datetime64(is_dates_only=self._is_dates_only)
formatter = get_format_datetime64(is_dates_only_=self._is_dates_only)
return lambda x: f"'{formatter(x)}'"

# --------------------------------------------------------------------
Expand Down
34 changes: 16 additions & 18 deletions pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
QUOTE_NONE,
QUOTE_NONNUMERIC,
)
import decimal
from decimal import Decimal
from functools import partial
from io import StringIO
import math
Expand Down Expand Up @@ -106,11 +106,7 @@
check_parent_directory,
stringify_path,
)
from pandas.io.formats.printing import (
adjoin,
justify,
pprint_thing,
)
from pandas.io.formats import printing

if TYPE_CHECKING:
from pandas import (
Expand Down Expand Up @@ -339,7 +335,7 @@ def _get_footer(self) -> str:
if footer:
footer += ", "

series_name = pprint_thing(name, escape_chars=("\t", "\r", "\n"))
series_name = printing.pprint_thing(name, escape_chars=("\t", "\r", "\n"))
footer += f"Name: {series_name}"

if self.length is True or (
Expand All @@ -354,7 +350,7 @@ def _get_footer(self) -> str:
if dtype_name:
if footer:
footer += ", "
footer += f"dtype: {pprint_thing(dtype_name)}"
footer += f"dtype: {printing.pprint_thing(dtype_name)}"

# level infos are added to the end and in a new line, like it is done
# for Categoricals
Expand Down Expand Up @@ -433,10 +429,12 @@ def len(self, text: str) -> int:
return len(text)

def justify(self, texts: Any, max_len: int, mode: str = "right") -> list[str]:
return justify(texts, max_len, mode=mode)
return printing.justify(texts, max_len, mode=mode)

def adjoin(self, space: int, *lists, **kwargs) -> str:
return adjoin(space, *lists, strlen=self.len, justfunc=self.justify, **kwargs)
return printing.adjoin(
space, *lists, strlen=self.len, justfunc=self.justify, **kwargs
)


class EastAsianTextAdjustment(TextAdjustment):
Expand Down Expand Up @@ -1375,7 +1373,7 @@ def _format_strings(self) -> list[str]:
else:
quote_strings = self.quoting is not None and self.quoting != QUOTE_NONE
formatter = partial(
pprint_thing,
printing.pprint_thing,
escape_chars=("\t", "\r", "\n"),
quote_strings=quote_strings,
)
Expand Down Expand Up @@ -1794,12 +1792,12 @@ def _format_datetime64_dateonly(


def get_format_datetime64(
is_dates_only: bool, nat_rep: str = "NaT", date_format: str | None = None
is_dates_only_: bool, nat_rep: str = "NaT", date_format: str | None = None
) -> Callable:
"""Return a formatter callable taking a datetime64 as input and providing
a string as output"""

if is_dates_only:
if is_dates_only_:
return lambda x: _format_datetime64_dateonly(
x, nat_rep=nat_rep, date_format=date_format
)
Expand Down Expand Up @@ -2071,12 +2069,12 @@ def __call__(self, num: float) -> str:

@return: engineering formatted string
"""
dnum = decimal.Decimal(str(num))
dnum = Decimal(str(num))

if decimal.Decimal.is_nan(dnum):
if Decimal.is_nan(dnum):
return "NaN"

if decimal.Decimal.is_infinite(dnum):
if Decimal.is_infinite(dnum):
return "inf"

sign = 1
Expand All @@ -2086,9 +2084,9 @@ def __call__(self, num: float) -> str:
dnum = -dnum

if dnum != 0:
pow10 = decimal.Decimal(int(math.floor(dnum.log10() / 3) * 3))
pow10 = Decimal(int(math.floor(dnum.log10() / 3) * 3))
else:
pow10 = decimal.Decimal(0)
pow10 = Decimal(0)

pow10 = pow10.min(max(self.ENG_PREFIXES.keys()))
pow10 = pow10.max(min(self.ENG_PREFIXES.keys()))
Expand Down