From 5b7ee86833f8a917ce8743dcf81fd9a8c64d418e Mon Sep 17 00:00:00 2001 From: H L Date: Tue, 22 Nov 2022 13:09:06 -0800 Subject: [PATCH 1/5] addressed pylint redfined-outer-name warning in files --- pandas/core/tools/datetimes.py | 12 +++++++----- pandas/io/formats/format.py | 24 ++++++++++++------------ 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/pandas/core/tools/datetimes.py b/pandas/core/tools/datetimes.py index 9b59c9ea43e45..464a532c68339 100644 --- a/pandas/core/tools/datetimes.py +++ b/pandas/core/tools/datetimes.py @@ -293,7 +293,9 @@ def _convert_and_box_cache( return _box_as_indexlike(result._values, utc=None, name=name) -def _return_parsed_timezone_results(result: np.ndarray, timezones, tz, name) -> Index: +def _return_parsed_timezone_results( + result: np.ndarray, timezone_arr, tz, name +) -> Index: """ Return results from array_strptime if a %z or %Z directive was passed. @@ -301,7 +303,7 @@ def _return_parsed_timezone_results(result: np.ndarray, timezones, tz, name) -> ---------- result : ndarray[int64] int64 date representations of the dates - timezones : ndarray + timezone_arr : ndarray pytz timezone objects tz : object None or pytz timezone object @@ -313,7 +315,7 @@ def _return_parsed_timezone_results(result: np.ndarray, timezones, tz, name) -> tz_result : Index-like of parsed dates with timezone """ tz_results = np.array( - [Timestamp(res).tz_localize(zone) for res, zone in zip(result, timezones)] + [Timestamp(res).tz_localize(zone) for res, zone in zip(result, timezone_arr)] ) if tz is not None: # Convert to the same tz @@ -470,7 +472,7 @@ def _array_strptime_with_fallback( utc = tz == "utc" try: - result, timezones = array_strptime(arg, fmt, exact=exact, errors=errors) + result, timezone_arr = array_strptime(arg, fmt, exact=exact, errors=errors) except OutOfBoundsDatetime: if errors == "raise": raise @@ -498,7 +500,7 @@ def _array_strptime_with_fallback( return None else: if "%Z" in fmt or "%z" in fmt: - return _return_parsed_timezone_results(result, timezones, tz, name) + return _return_parsed_timezone_results(result, timezone_arr, tz, name) return _box_as_indexlike(result, utc=utc, name=name) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index cdc21f04da43a..f7950b8c343a8 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -9,7 +9,7 @@ QUOTE_NONE, QUOTE_NONNUMERIC, ) -import decimal +import decimal as decimal_import from functools import partial from io import StringIO import math @@ -108,7 +108,7 @@ ) from pandas.io.formats.printing import ( adjoin, - justify, + justify as printing_justify, pprint_thing, ) @@ -433,7 +433,7 @@ 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) @@ -1794,12 +1794,12 @@ def _format_datetime64_dateonly( def get_format_datetime64( - is_dates_only: bool, nat_rep: str = "NaT", date_format: str | None = None + is_only_dates: 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_only_dates: return lambda x: _format_datetime64_dateonly( x, nat_rep=nat_rep, date_format=date_format ) @@ -1933,7 +1933,7 @@ def just(x: str) -> str: return x strings = [just(x) for x in strings] - result = adjustment.justify(strings, max_len, mode=justify) + result = adjustment.ifp_justify(strings, max_len, mode=justify) return result @@ -2067,16 +2067,16 @@ def __call__(self, num: float) -> str: @param num: the value to represent @type num: either a numeric value or a string that can be converted to - a numeric value (as per decimal.Decimal constructor) + a numeric value (as per decimal_import.Decimal constructor) @return: engineering formatted string """ - dnum = decimal.Decimal(str(num)) + dnum = decimal_import.Decimal(str(num)) - if decimal.Decimal.is_nan(dnum): + if decimal_import.Decimal.is_nan(dnum): return "NaN" - if decimal.Decimal.is_infinite(dnum): + if decimal_import.Decimal.is_infinite(dnum): return "inf" sign = 1 @@ -2086,9 +2086,9 @@ def __call__(self, num: float) -> str: dnum = -dnum if dnum != 0: - pow10 = decimal.Decimal(int(math.floor(dnum.log10() / 3) * 3)) + pow10 = decimal_import.Decimal(int(math.floor(dnum.log10() / 3) * 3)) else: - pow10 = decimal.Decimal(0) + pow10 = decimal_import.Decimal(0) pow10 = pow10.min(max(self.ENG_PREFIXES.keys())) pow10 = pow10.max(min(self.ENG_PREFIXES.keys())) From 7ed900e32a529e7264fc6356522e9e1c016247cd Mon Sep 17 00:00:00 2001 From: H L Date: Tue, 22 Nov 2022 13:14:15 -0800 Subject: [PATCH 2/5] addressed pylint redefined-outer-name warning in files --- pandas/io/formats/format.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index f7950b8c343a8..4098ff910c25a 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1933,7 +1933,7 @@ def just(x: str) -> str: return x strings = [just(x) for x in strings] - result = adjustment.ifp_justify(strings, max_len, mode=justify) + result = adjustment.justify(strings, max_len, mode=justify) return result From 82c9e347fa195586966b3c0412fb3347944d26be Mon Sep 17 00:00:00 2001 From: H L Date: Tue, 22 Nov 2022 14:17:37 -0800 Subject: [PATCH 3/5] addressed pylint redefined_out_name warning in datetimes.py --- pandas/core/tools/datetimes.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pandas/core/tools/datetimes.py b/pandas/core/tools/datetimes.py index 9b59c9ea43e45..464a532c68339 100644 --- a/pandas/core/tools/datetimes.py +++ b/pandas/core/tools/datetimes.py @@ -293,7 +293,9 @@ def _convert_and_box_cache( return _box_as_indexlike(result._values, utc=None, name=name) -def _return_parsed_timezone_results(result: np.ndarray, timezones, tz, name) -> Index: +def _return_parsed_timezone_results( + result: np.ndarray, timezone_arr, tz, name +) -> Index: """ Return results from array_strptime if a %z or %Z directive was passed. @@ -301,7 +303,7 @@ def _return_parsed_timezone_results(result: np.ndarray, timezones, tz, name) -> ---------- result : ndarray[int64] int64 date representations of the dates - timezones : ndarray + timezone_arr : ndarray pytz timezone objects tz : object None or pytz timezone object @@ -313,7 +315,7 @@ def _return_parsed_timezone_results(result: np.ndarray, timezones, tz, name) -> tz_result : Index-like of parsed dates with timezone """ tz_results = np.array( - [Timestamp(res).tz_localize(zone) for res, zone in zip(result, timezones)] + [Timestamp(res).tz_localize(zone) for res, zone in zip(result, timezone_arr)] ) if tz is not None: # Convert to the same tz @@ -470,7 +472,7 @@ def _array_strptime_with_fallback( utc = tz == "utc" try: - result, timezones = array_strptime(arg, fmt, exact=exact, errors=errors) + result, timezone_arr = array_strptime(arg, fmt, exact=exact, errors=errors) except OutOfBoundsDatetime: if errors == "raise": raise @@ -498,7 +500,7 @@ def _array_strptime_with_fallback( return None else: if "%Z" in fmt or "%z" in fmt: - return _return_parsed_timezone_results(result, timezones, tz, name) + return _return_parsed_timezone_results(result, timezone_arr, tz, name) return _box_as_indexlike(result, utc=utc, name=name) From a75464e683b93ee589fe4e429a5cd61f5cf1ae7f Mon Sep 17 00:00:00 2001 From: H L Date: Tue, 22 Nov 2022 14:24:39 -0800 Subject: [PATCH 4/5] addressed pylint redefined_out_name warning in datetimes.py --- pandas/io/formats/format.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 4098ff910c25a..cdc21f04da43a 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -9,7 +9,7 @@ QUOTE_NONE, QUOTE_NONNUMERIC, ) -import decimal as decimal_import +import decimal from functools import partial from io import StringIO import math @@ -108,7 +108,7 @@ ) from pandas.io.formats.printing import ( adjoin, - justify as printing_justify, + justify, pprint_thing, ) @@ -433,7 +433,7 @@ def len(self, text: str) -> int: return len(text) def justify(self, texts: Any, max_len: int, mode: str = "right") -> list[str]: - return printing_justify(texts, max_len, mode=mode) + return 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) @@ -1794,12 +1794,12 @@ def _format_datetime64_dateonly( def get_format_datetime64( - is_only_dates: 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_only_dates: + if is_dates_only: return lambda x: _format_datetime64_dateonly( x, nat_rep=nat_rep, date_format=date_format ) @@ -2067,16 +2067,16 @@ def __call__(self, num: float) -> str: @param num: the value to represent @type num: either a numeric value or a string that can be converted to - a numeric value (as per decimal_import.Decimal constructor) + a numeric value (as per decimal.Decimal constructor) @return: engineering formatted string """ - dnum = decimal_import.Decimal(str(num)) + dnum = decimal.Decimal(str(num)) - if decimal_import.Decimal.is_nan(dnum): + if decimal.Decimal.is_nan(dnum): return "NaN" - if decimal_import.Decimal.is_infinite(dnum): + if decimal.Decimal.is_infinite(dnum): return "inf" sign = 1 @@ -2086,9 +2086,9 @@ def __call__(self, num: float) -> str: dnum = -dnum if dnum != 0: - pow10 = decimal_import.Decimal(int(math.floor(dnum.log10() / 3) * 3)) + pow10 = decimal.Decimal(int(math.floor(dnum.log10() / 3) * 3)) else: - pow10 = decimal_import.Decimal(0) + pow10 = decimal.Decimal(0) pow10 = pow10.min(max(self.ENG_PREFIXES.keys())) pow10 = pow10.max(min(self.ENG_PREFIXES.keys())) From 93281dfbc726127e1cc699f96eb548a9271dbf10 Mon Sep 17 00:00:00 2001 From: H L Date: Wed, 23 Nov 2022 10:40:51 -0800 Subject: [PATCH 5/5] updated pylint fix by renaming import timezones to libtimezones --- pandas/core/tools/datetimes.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/pandas/core/tools/datetimes.py b/pandas/core/tools/datetimes.py index 464a532c68339..90f0425697ec5 100644 --- a/pandas/core/tools/datetimes.py +++ b/pandas/core/tools/datetimes.py @@ -26,7 +26,7 @@ iNaT, nat_strings, parsing, - timezones, + timezones as libtimezones, ) from pandas._libs.tslibs.parsing import ( DateParseError, @@ -293,9 +293,7 @@ def _convert_and_box_cache( return _box_as_indexlike(result._values, utc=None, name=name) -def _return_parsed_timezone_results( - result: np.ndarray, timezone_arr, tz, name -) -> Index: +def _return_parsed_timezone_results(result: np.ndarray, timezones, tz, name) -> Index: """ Return results from array_strptime if a %z or %Z directive was passed. @@ -303,7 +301,7 @@ def _return_parsed_timezone_results( ---------- result : ndarray[int64] int64 date representations of the dates - timezone_arr : ndarray + timezones : ndarray pytz timezone objects tz : object None or pytz timezone object @@ -315,7 +313,7 @@ def _return_parsed_timezone_results( tz_result : Index-like of parsed dates with timezone """ tz_results = np.array( - [Timestamp(res).tz_localize(zone) for res, zone in zip(result, timezone_arr)] + [Timestamp(res).tz_localize(zone) for res, zone in zip(result, timezones)] ) if tz is not None: # Convert to the same tz @@ -402,7 +400,7 @@ def _convert_listlike_datetimes( # NB: this must come after unit transformation orig_arg = arg try: - arg, _ = maybe_convert_dtype(arg, copy=False, tz=timezones.maybe_get_tz(tz)) + arg, _ = maybe_convert_dtype(arg, copy=False, tz=libtimezones.maybe_get_tz(tz)) except TypeError: if errors == "coerce": npvalues = np.array(["NaT"], dtype="datetime64[ns]").repeat(len(arg)) @@ -472,7 +470,7 @@ def _array_strptime_with_fallback( utc = tz == "utc" try: - result, timezone_arr = array_strptime(arg, fmt, exact=exact, errors=errors) + result, timezones = array_strptime(arg, fmt, exact=exact, errors=errors) except OutOfBoundsDatetime: if errors == "raise": raise @@ -500,7 +498,7 @@ def _array_strptime_with_fallback( return None else: if "%Z" in fmt or "%z" in fmt: - return _return_parsed_timezone_results(result, timezone_arr, tz, name) + return _return_parsed_timezone_results(result, timezones, tz, name) return _box_as_indexlike(result, utc=utc, name=name)