Skip to content

Commit 2f7b42d

Browse files
STYLE: Fixed redefined-outer-name linting issue (#49675)
* STYLE: Fixed redefined-outer-name linting issue * Changes in xml.py and datetimes.py addressed
1 parent 6fac28d commit 2f7b42d

File tree

3 files changed

+11
-20
lines changed

3 files changed

+11
-20
lines changed

pandas/core/indexes/datetimes.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
from __future__ import annotations
22

3-
from datetime import (
4-
date,
5-
datetime,
6-
time,
7-
timedelta,
8-
tzinfo,
9-
)
3+
import datetime as dt
104
import operator
115
from typing import (
126
TYPE_CHECKING,
@@ -257,7 +251,7 @@ def _engine_type(self) -> type[libindex.DatetimeEngine]:
257251

258252
_data: DatetimeArray
259253
inferred_freq: str | None
260-
tz: tzinfo | None
254+
tz: dt.tzinfo | None
261255

262256
# --------------------------------------------------------------------
263257
# methods that dispatch to DatetimeArray and wrap result
@@ -514,7 +508,7 @@ def snap(self, freq: Frequency = "S") -> DatetimeIndex:
514508
# --------------------------------------------------------------------
515509
# Indexing Methods
516510

517-
def _parsed_string_to_bounds(self, reso: Resolution, parsed: datetime):
511+
def _parsed_string_to_bounds(self, reso: Resolution, parsed: dt.datetime):
518512
"""
519513
Calculate datetime bounds for parsed time string and its resolution.
520514
@@ -604,13 +598,13 @@ def get_loc(self, key, method=None, tolerance=None):
604598

605599
key = self._maybe_cast_for_get_loc(key)
606600

607-
elif isinstance(key, timedelta):
601+
elif isinstance(key, dt.timedelta):
608602
# GH#20464
609603
raise TypeError(
610604
f"Cannot index {type(self).__name__} with {type(key).__name__}"
611605
)
612606

613-
elif isinstance(key, time):
607+
elif isinstance(key, dt.time):
614608
if method is not None:
615609
raise NotImplementedError(
616610
"cannot yet lookup inexact labels when key is a time object"
@@ -648,7 +642,7 @@ def _maybe_cast_for_get_loc(self, key) -> Timestamp:
648642
def _maybe_cast_slice_bound(self, label, side: str):
649643

650644
# GH#42855 handle date here instead of get_slice_bound
651-
if isinstance(label, date) and not isinstance(label, datetime):
645+
if isinstance(label, dt.date) and not isinstance(label, dt.datetime):
652646
# Pandas supports slicing with dates, treated as datetimes at midnight.
653647
# https://github.com/pandas-dev/pandas/issues/31501
654648
label = Timestamp(label).to_pydatetime()
@@ -674,12 +668,12 @@ def slice_indexer(self, start=None, end=None, step=None):
674668
# For historical reasons DatetimeIndex supports slices between two
675669
# instances of datetime.time as if it were applying a slice mask to
676670
# an array of (self.hour, self.minute, self.seconds, self.microsecond).
677-
if isinstance(start, time) and isinstance(end, time):
671+
if isinstance(start, dt.time) and isinstance(end, dt.time):
678672
if step is not None and step != 1:
679673
raise ValueError("Must have step size of 1 with time slices")
680674
return self.indexer_between_time(start, end)
681675

682-
if isinstance(start, time) or isinstance(end, time):
676+
if isinstance(start, dt.time) or isinstance(end, dt.time):
683677
raise KeyError("Cannot mix time and non-time slice keys")
684678

685679
def check_str_or_none(point) -> bool:
@@ -1092,6 +1086,6 @@ def bdate_range(
10921086
)
10931087

10941088

1095-
def _time_to_micros(time_obj: time) -> int:
1089+
def _time_to_micros(time_obj: dt.time) -> int:
10961090
seconds = time_obj.hour * 60 * 60 + 60 * time_obj.minute + time_obj.second
10971091
return 1_000_000 * seconds + time_obj.microsecond

pandas/io/formats/xml.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,14 +419,12 @@ def add_declaration(self) -> bytes:
419419
"""
420420
decl = f'<?xml version="1.0" encoding="{self.encoding}"?>\n'
421421

422-
doc = (
422+
return (
423423
self.out_xml
424424
if self.out_xml.startswith(b"<?xml")
425425
else decl.encode(self.encoding) + self.out_xml
426426
)
427427

428-
return doc
429-
430428
def remove_declaration(self) -> bytes:
431429
"""
432430
Remove xml declaration.

pandas/io/json/_table_schema.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
)
1313
import warnings
1414

15-
from pandas._libs import json
15+
from pandas._libs.json import loads
1616
from pandas._typing import (
1717
DtypeObj,
1818
JSONSerializable,
@@ -41,7 +41,6 @@
4141
from pandas import Series
4242
from pandas.core.indexes.multi import MultiIndex
4343

44-
loads = json.loads
4544

4645
TABLE_SCHEMA_VERSION = "1.4.0"
4746

0 commit comments

Comments
 (0)