Skip to content

Commit 0d9be88

Browse files
authored
post-merge fixup (#37112)
1 parent 9c202a1 commit 0d9be88

File tree

12 files changed

+58
-65
lines changed

12 files changed

+58
-65
lines changed

pandas/core/dtypes/cast.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77

88
import numpy as np
99

10-
from pandas._libs import lib, tslib, tslibs
10+
from pandas._libs import lib, tslib
1111
from pandas._libs.tslibs import (
1212
NaT,
1313
OutOfBoundsDatetime,
1414
Period,
1515
Timedelta,
1616
Timestamp,
17+
conversion,
1718
iNaT,
1819
ints_to_pydatetime,
20+
ints_to_pytimedelta,
1921
)
2022
from pandas._libs.tslibs.timezones import tz_compare
2123
from pandas._typing import ArrayLike, Dtype, DtypeObj
@@ -552,7 +554,7 @@ def maybe_promote(dtype, fill_value=np.nan):
552554
dtype = np.dtype(np.object_)
553555
else:
554556
try:
555-
fill_value = tslibs.Timestamp(fill_value).to_datetime64()
557+
fill_value = Timestamp(fill_value).to_datetime64()
556558
except (TypeError, ValueError):
557559
dtype = np.dtype(np.object_)
558560
elif issubclass(dtype.type, np.timedelta64):
@@ -565,7 +567,7 @@ def maybe_promote(dtype, fill_value=np.nan):
565567
dtype = np.dtype(np.object_)
566568
else:
567569
try:
568-
fv = tslibs.Timedelta(fill_value)
570+
fv = Timedelta(fill_value)
569571
except ValueError:
570572
dtype = np.dtype(np.object_)
571573
else:
@@ -738,8 +740,8 @@ def infer_dtype_from_scalar(val, pandas_dtype: bool = False) -> Tuple[DtypeObj,
738740
dtype = np.dtype(object)
739741

740742
elif isinstance(val, (np.datetime64, datetime)):
741-
val = tslibs.Timestamp(val)
742-
if val is tslibs.NaT or val.tz is None:
743+
val = Timestamp(val)
744+
if val is NaT or val.tz is None:
743745
dtype = np.dtype("M8[ns]")
744746
else:
745747
if pandas_dtype:
@@ -750,7 +752,7 @@ def infer_dtype_from_scalar(val, pandas_dtype: bool = False) -> Tuple[DtypeObj,
750752
val = val.value
751753

752754
elif isinstance(val, (np.timedelta64, timedelta)):
753-
val = tslibs.Timedelta(val).value
755+
val = Timedelta(val).value
754756
dtype = np.dtype("m8[ns]")
755757

756758
elif is_bool(val):
@@ -941,9 +943,9 @@ def conv(r, dtype):
941943
if np.any(isna(r)):
942944
pass
943945
elif dtype == DT64NS_DTYPE:
944-
r = tslibs.Timestamp(r)
946+
r = Timestamp(r)
945947
elif dtype == TD64NS_DTYPE:
946-
r = tslibs.Timedelta(r)
948+
r = Timedelta(r)
947949
elif dtype == np.bool_:
948950
# messy. non 0/1 integers do not get converted.
949951
if is_integer(r) and r not in [0, 1]:
@@ -1006,7 +1008,7 @@ def astype_nansafe(arr, dtype, copy: bool = True, skipna: bool = False):
10061008

10071009
elif is_timedelta64_dtype(arr):
10081010
if is_object_dtype(dtype):
1009-
return tslibs.ints_to_pytimedelta(arr.view(np.int64))
1011+
return ints_to_pytimedelta(arr.view(np.int64))
10101012
elif dtype == np.int64:
10111013
if isna(arr).any():
10121014
raise ValueError("Cannot convert NaT values to integer")
@@ -1317,8 +1319,6 @@ def try_datetime(v):
13171319
# we might have a sequence of the same-datetimes with tz's
13181320
# if so coerce to a DatetimeIndex; if they are not the same,
13191321
# then these stay as object dtype, xref GH19671
1320-
from pandas._libs.tslibs import conversion
1321-
13221322
from pandas import DatetimeIndex
13231323

13241324
try:
@@ -1492,7 +1492,7 @@ def maybe_cast_to_datetime(value, dtype, errors: str = "raise"):
14921492
dtype = value.dtype
14931493

14941494
if dtype.kind == "M" and dtype != DT64NS_DTYPE:
1495-
value = tslibs.conversion.ensure_datetime64ns(value)
1495+
value = conversion.ensure_datetime64ns(value)
14961496

14971497
elif dtype.kind == "m" and dtype != TD64NS_DTYPE:
14981498
value = to_timedelta(value)

pandas/core/dtypes/dtypes.py

+4-10
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,6 @@ def __repr__(self) -> str_type:
406406

407407
@staticmethod
408408
def _hash_categories(categories, ordered: Ordered = True) -> int:
409-
from pandas.core.dtypes.common import DT64NS_DTYPE, is_datetime64tz_dtype
410-
411409
from pandas.core.util.hashing import (
412410
combine_hash_arrays,
413411
hash_array,
@@ -430,9 +428,9 @@ def _hash_categories(categories, ordered: Ordered = True) -> int:
430428
hashed = hash((tuple(categories), ordered))
431429
return hashed
432430

433-
if is_datetime64tz_dtype(categories.dtype):
431+
if DatetimeTZDtype.is_dtype(categories.dtype):
434432
# Avoid future warning.
435-
categories = categories.astype(DT64NS_DTYPE)
433+
categories = categories.astype("datetime64[ns]")
436434

437435
cat_array = hash_array(np.asarray(categories), categorize=False)
438436
if ordered:
@@ -1011,11 +1009,7 @@ class IntervalDtype(PandasExtensionDtype):
10111009
_cache: Dict[str_type, PandasExtensionDtype] = {}
10121010

10131011
def __new__(cls, subtype=None):
1014-
from pandas.core.dtypes.common import (
1015-
is_categorical_dtype,
1016-
is_string_dtype,
1017-
pandas_dtype,
1018-
)
1012+
from pandas.core.dtypes.common import is_string_dtype, pandas_dtype
10191013

10201014
if isinstance(subtype, IntervalDtype):
10211015
return subtype
@@ -1038,7 +1032,7 @@ def __new__(cls, subtype=None):
10381032
except TypeError as err:
10391033
raise TypeError("could not construct IntervalDtype") from err
10401034

1041-
if is_categorical_dtype(subtype) or is_string_dtype(subtype):
1035+
if CategoricalDtype.is_dtype(subtype) or is_string_dtype(subtype):
10421036
# GH 19016
10431037
msg = (
10441038
"category, object, and string subtypes are not supported "

pandas/core/frame.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
)
148148
from pandas.core.reshape.melt import melt
149149
from pandas.core.series import Series
150+
from pandas.core.sorting import get_group_index, lexsort_indexer, nargsort
150151

151152
from pandas.io.common import get_filepath_or_buffer
152153
from pandas.io.formats import console, format as fmt
@@ -5251,8 +5252,6 @@ def duplicated(
52515252
"""
52525253
from pandas._libs.hashtable import SIZE_HINT_LIMIT, duplicated_int64
52535254

5254-
from pandas.core.sorting import get_group_index
5255-
52565255
if self.empty:
52575256
return self._constructor_sliced(dtype=bool)
52585257

@@ -5315,7 +5314,6 @@ def sort_values( # type: ignore[override]
53155314
f"Length of ascending ({len(ascending)}) != length of by ({len(by)})"
53165315
)
53175316
if len(by) > 1:
5318-
from pandas.core.sorting import lexsort_indexer
53195317

53205318
keys = [self._get_label_or_level_values(x, axis=axis) for x in by]
53215319

@@ -5328,7 +5326,6 @@ def sort_values( # type: ignore[override]
53285326
)
53295327
indexer = ensure_platform_int(indexer)
53305328
else:
5331-
from pandas.core.sorting import nargsort
53325329

53335330
by = by[0]
53345331
k = self._get_label_or_level_values(by, axis=axis)

pandas/core/generic.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from pandas._config import config
3535

3636
from pandas._libs import lib
37-
from pandas._libs.tslibs import Tick, Timestamp, to_offset
37+
from pandas._libs.tslibs import Period, Tick, Timestamp, to_offset
3838
from pandas._typing import (
3939
Axis,
4040
CompressionOptions,
@@ -86,17 +86,21 @@
8686
from pandas.core.dtypes.missing import isna, notna
8787

8888
import pandas as pd
89-
from pandas.core import missing, nanops
89+
from pandas.core import indexing, missing, nanops
9090
import pandas.core.algorithms as algos
9191
from pandas.core.base import PandasObject, SelectionMixin
9292
import pandas.core.common as com
9393
from pandas.core.construction import create_series_with_explicit_dtype
9494
from pandas.core.flags import Flags
9595
from pandas.core.indexes import base as ibase
96-
from pandas.core.indexes.api import Index, MultiIndex, RangeIndex, ensure_index
97-
from pandas.core.indexes.datetimes import DatetimeIndex
98-
from pandas.core.indexes.period import Period, PeriodIndex
99-
import pandas.core.indexing as indexing
96+
from pandas.core.indexes.api import (
97+
DatetimeIndex,
98+
Index,
99+
MultiIndex,
100+
PeriodIndex,
101+
RangeIndex,
102+
ensure_index,
103+
)
100104
from pandas.core.internals import BlockManager
101105
from pandas.core.missing import find_valid_index
102106
from pandas.core.ops import align_method_FRAME

pandas/core/indexes/base.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,13 @@
2323
from pandas._libs import algos as libalgos, index as libindex, lib
2424
import pandas._libs.join as libjoin
2525
from pandas._libs.lib import is_datetime_array, no_default
26-
from pandas._libs.tslibs import OutOfBoundsDatetime, Timestamp
27-
from pandas._libs.tslibs.period import IncompatibleFrequency
26+
from pandas._libs.tslibs import IncompatibleFrequency, OutOfBoundsDatetime, Timestamp
2827
from pandas._libs.tslibs.timezones import tz_compare
2928
from pandas._typing import AnyArrayLike, Dtype, DtypeObj, Label
3029
from pandas.compat.numpy import function as nv
3130
from pandas.errors import DuplicateLabelError, InvalidIndexError
3231
from pandas.util._decorators import Appender, cache_readonly, doc
3332

34-
from pandas.core.dtypes import concat as _concat
3533
from pandas.core.dtypes.cast import (
3634
maybe_cast_to_integer_array,
3735
validate_numeric_casting,
@@ -77,7 +75,7 @@
7775
)
7876
from pandas.core.dtypes.missing import array_equivalent, isna
7977

80-
from pandas.core import ops
78+
from pandas.core import missing, ops
8179
from pandas.core.accessor import CachedAccessor
8280
import pandas.core.algorithms as algos
8381
from pandas.core.arrays import Categorical, ExtensionArray
@@ -86,7 +84,6 @@
8684
import pandas.core.common as com
8785
from pandas.core.indexers import deprecate_ndim_indexing
8886
from pandas.core.indexes.frozen import FrozenList
89-
import pandas.core.missing as missing
9087
from pandas.core.ops import get_op_result_name
9188
from pandas.core.ops.invalid import make_invalid_op
9289
from pandas.core.sorting import ensure_key_mapped, nargsort
@@ -4205,7 +4202,7 @@ def _concat(self, to_concat, name):
42054202
"""
42064203
to_concat = [x._values if isinstance(x, Index) else x for x in to_concat]
42074204

4208-
result = _concat.concat_compat(to_concat)
4205+
result = concat_compat(to_concat)
42094206
return Index(result, name=name)
42104207

42114208
def putmask(self, mask, value):

pandas/core/indexes/multi.py

-1
Original file line numberDiff line numberDiff line change
@@ -3093,7 +3093,6 @@ def get_locs(self, seq):
30933093
>>> mi.get_locs([[True, False, True], slice('e', 'f')]) # doctest: +SKIP
30943094
array([2], dtype=int64)
30953095
"""
3096-
from pandas.core.indexes.numeric import Int64Index
30973096

30983097
# must be lexsorted to at least as many levels
30993098
true_slices = [i for (i, s) in enumerate(com.is_true_slices(seq)) if s]

pandas/core/internals/blocks.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
import numpy as np
88

9-
from pandas._libs import NaT, algos as libalgos, lib, writers
10-
import pandas._libs.internals as libinternals
9+
from pandas._libs import NaT, algos as libalgos, internals as libinternals, lib, writers
1110
from pandas._libs.internals import BlockPlacement
1211
from pandas._libs.tslibs import conversion
1312
from pandas._libs.tslibs.timezones import tz_compare

pandas/core/reshape/merge.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
import numpy as np
1313

14-
from pandas._libs import Timedelta, hashtable as libhashtable, lib
15-
import pandas._libs.join as libjoin
14+
from pandas._libs import Timedelta, hashtable as libhashtable, join as libjoin, lib
1615
from pandas._typing import ArrayLike, FrameOrSeries, FrameOrSeriesUnion
1716
from pandas.errors import MergeError
1817
from pandas.util._decorators import Appender, Substitution

pandas/core/series.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
remove_na_arraylike,
6868
)
6969

70-
import pandas as pd
7170
from pandas.core import algorithms, base, generic, nanops, ops
7271
from pandas.core.accessor import CachedAccessor
7372
from pandas.core.aggregation import aggregate, transform
@@ -76,6 +75,7 @@
7675
from pandas.core.arrays.sparse import SparseAccessor
7776
import pandas.core.common as com
7877
from pandas.core.construction import (
78+
array as pd_array,
7979
create_series_with_explicit_dtype,
8080
extract_array,
8181
is_empty_data,
@@ -4193,7 +4193,7 @@ def f(x):
41934193
if len(mapped) and isinstance(mapped[0], Series):
41944194
# GH 25959 use pd.array instead of tolist
41954195
# so extension arrays can be used
4196-
return self._constructor_expanddim(pd.array(mapped), index=self.index)
4196+
return self._constructor_expanddim(pd_array(mapped), index=self.index)
41974197
else:
41984198
return self._constructor(mapped, index=self.index).__finalize__(
41994199
self, method="apply"

0 commit comments

Comments
 (0)