Skip to content

Commit c3a257c

Browse files
authored
STYLE #49656: fixed redefined-outer-name linting issue to format.py (#49937)
* changed decimal module import, Decimal function call in EngFormatter class __call__ function * changed name of parameter for get_format_datetime64 to avoid redefined outer name conflict with is_dates_only function * change in argument name for call to get_format_datetime64 to match change in datetimes.py * removed import - justify function not used and creating redefined outer name conflict with justify functions defined for TextAdjustment and EastAsianTextAdjustment classes * replaced justify import with alias to avoid redefined-outer-name conflict * renamed imports from printing module * function renamed to is_dates_only_, returned argument for get_formate_datetime64 to is_dates_only * changes in datetimes.py to reflect function and argument names in format.py * argument and function names swapped * function name is is_dates_only, argument for get_format_datetime64 is is_dates_only_ * Update .pre-commit-config.yaml removed format and datetimes files
1 parent 5422716 commit c3a257c

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ repos:
7575
|^pandas/util/_test_decorators\.py # keep excluded
7676
|^pandas/_version\.py # keep excluded
7777
|^pandas/conftest\.py # keep excluded
78-
|^pandas/core/tools/datetimes\.py
79-
|^pandas/io/formats/format\.py
8078
|^pandas/core/generic\.py
8179
args: [--disable=all, --enable=redefined-outer-name]
8280
stages: [manual]

pandas/core/indexes/datetimes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def _is_comparable_dtype(self, dtype: DtypeObj) -> bool:
384384
def _formatter_func(self):
385385
from pandas.io.formats.format import get_format_datetime64
386386

387-
formatter = get_format_datetime64(is_dates_only=self._is_dates_only)
387+
formatter = get_format_datetime64(is_dates_only_=self._is_dates_only)
388388
return lambda x: f"'{formatter(x)}'"
389389

390390
# --------------------------------------------------------------------

pandas/io/formats/format.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
QUOTE_NONE,
1010
QUOTE_NONNUMERIC,
1111
)
12-
import decimal
12+
from decimal import Decimal
1313
from functools import partial
1414
from io import StringIO
1515
import math
@@ -106,11 +106,7 @@
106106
check_parent_directory,
107107
stringify_path,
108108
)
109-
from pandas.io.formats.printing import (
110-
adjoin,
111-
justify,
112-
pprint_thing,
113-
)
109+
from pandas.io.formats import printing
114110

115111
if TYPE_CHECKING:
116112
from pandas import (
@@ -339,7 +335,7 @@ def _get_footer(self) -> str:
339335
if footer:
340336
footer += ", "
341337

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

345341
if self.length is True or (
@@ -354,7 +350,7 @@ def _get_footer(self) -> str:
354350
if dtype_name:
355351
if footer:
356352
footer += ", "
357-
footer += f"dtype: {pprint_thing(dtype_name)}"
353+
footer += f"dtype: {printing.pprint_thing(dtype_name)}"
358354

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

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

438434
def adjoin(self, space: int, *lists, **kwargs) -> str:
439-
return adjoin(space, *lists, strlen=self.len, justfunc=self.justify, **kwargs)
435+
return printing.adjoin(
436+
space, *lists, strlen=self.len, justfunc=self.justify, **kwargs
437+
)
440438

441439

442440
class EastAsianTextAdjustment(TextAdjustment):
@@ -1375,7 +1373,7 @@ def _format_strings(self) -> list[str]:
13751373
else:
13761374
quote_strings = self.quoting is not None and self.quoting != QUOTE_NONE
13771375
formatter = partial(
1378-
pprint_thing,
1376+
printing.pprint_thing,
13791377
escape_chars=("\t", "\r", "\n"),
13801378
quote_strings=quote_strings,
13811379
)
@@ -1794,12 +1792,12 @@ def _format_datetime64_dateonly(
17941792

17951793

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

1802-
if is_dates_only:
1800+
if is_dates_only_:
18031801
return lambda x: _format_datetime64_dateonly(
18041802
x, nat_rep=nat_rep, date_format=date_format
18051803
)
@@ -2071,12 +2069,12 @@ def __call__(self, num: float) -> str:
20712069
20722070
@return: engineering formatted string
20732071
"""
2074-
dnum = decimal.Decimal(str(num))
2072+
dnum = Decimal(str(num))
20752073

2076-
if decimal.Decimal.is_nan(dnum):
2074+
if Decimal.is_nan(dnum):
20772075
return "NaN"
20782076

2079-
if decimal.Decimal.is_infinite(dnum):
2077+
if Decimal.is_infinite(dnum):
20802078
return "inf"
20812079

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

20882086
if dnum != 0:
2089-
pow10 = decimal.Decimal(int(math.floor(dnum.log10() / 3) * 3))
2087+
pow10 = Decimal(int(math.floor(dnum.log10() / 3) * 3))
20902088
else:
2091-
pow10 = decimal.Decimal(0)
2089+
pow10 = Decimal(0)
20922090

20932091
pow10 = pow10.min(max(self.ENG_PREFIXES.keys()))
20942092
pow10 = pow10.max(min(self.ENG_PREFIXES.keys()))

0 commit comments

Comments
 (0)