Skip to content

STYLE: Fixed redefined-outer-name linting issue #49675

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 3 commits into from
Nov 13, 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
24 changes: 9 additions & 15 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
from __future__ import annotations

from datetime import (
date,
datetime,
time,
timedelta,
tzinfo,
)
import datetime as dt
import operator
from typing import (
TYPE_CHECKING,
Expand Down Expand Up @@ -257,7 +251,7 @@ def _engine_type(self) -> type[libindex.DatetimeEngine]:

_data: DatetimeArray
inferred_freq: str | None
tz: tzinfo | None
tz: dt.tzinfo | None

# --------------------------------------------------------------------
# methods that dispatch to DatetimeArray and wrap result
Expand Down Expand Up @@ -514,7 +508,7 @@ def snap(self, freq: Frequency = "S") -> DatetimeIndex:
# --------------------------------------------------------------------
# Indexing Methods

def _parsed_string_to_bounds(self, reso: Resolution, parsed: datetime):
def _parsed_string_to_bounds(self, reso: Resolution, parsed: dt.datetime):
"""
Calculate datetime bounds for parsed time string and its resolution.

Expand Down Expand Up @@ -604,13 +598,13 @@ def get_loc(self, key, method=None, tolerance=None):

key = self._maybe_cast_for_get_loc(key)

elif isinstance(key, timedelta):
elif isinstance(key, dt.timedelta):
# GH#20464
raise TypeError(
f"Cannot index {type(self).__name__} with {type(key).__name__}"
)

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

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

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

def check_str_or_none(point) -> bool:
Expand Down Expand Up @@ -1092,6 +1086,6 @@ def bdate_range(
)


def _time_to_micros(time_obj: time) -> int:
def _time_to_micros(time_obj: dt.time) -> int:
seconds = time_obj.hour * 60 * 60 + 60 * time_obj.minute + time_obj.second
return 1_000_000 * seconds + time_obj.microsecond
4 changes: 1 addition & 3 deletions pandas/io/formats/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,14 +419,12 @@ def add_declaration(self) -> bytes:
"""
decl = f'<?xml version="1.0" encoding="{self.encoding}"?>\n'

doc = (
return (
self.out_xml
if self.out_xml.startswith(b"<?xml")
else decl.encode(self.encoding) + self.out_xml
)

return doc

def remove_declaration(self) -> bytes:
"""
Remove xml declaration.
Expand Down
3 changes: 1 addition & 2 deletions pandas/io/json/_table_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)
import warnings

from pandas._libs import json
from pandas._libs.json import loads
from pandas._typing import (
DtypeObj,
JSONSerializable,
Expand Down Expand Up @@ -41,7 +41,6 @@
from pandas import Series
from pandas.core.indexes.multi import MultiIndex

loads = json.loads

TABLE_SCHEMA_VERSION = "1.4.0"

Expand Down