diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 3a00301fbc042..b2242191798b1 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -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, @@ -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 @@ -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. @@ -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" @@ -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() @@ -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: @@ -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 diff --git a/pandas/io/formats/xml.py b/pandas/io/formats/xml.py index eb1835f0392b0..60831b38dba31 100644 --- a/pandas/io/formats/xml.py +++ b/pandas/io/formats/xml.py @@ -419,14 +419,12 @@ def add_declaration(self) -> bytes: """ decl = f'\n' - doc = ( + return ( self.out_xml if self.out_xml.startswith(b" bytes: """ Remove xml declaration. diff --git a/pandas/io/json/_table_schema.py b/pandas/io/json/_table_schema.py index e1b8388788143..88ff8c699cc49 100644 --- a/pandas/io/json/_table_schema.py +++ b/pandas/io/json/_table_schema.py @@ -12,7 +12,7 @@ ) import warnings -from pandas._libs import json +from pandas._libs.json import loads from pandas._typing import ( DtypeObj, JSONSerializable, @@ -41,7 +41,6 @@ from pandas import Series from pandas.core.indexes.multi import MultiIndex -loads = json.loads TABLE_SCHEMA_VERSION = "1.4.0"