Skip to content

CLN: runtime imports #37112

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 1 commit into from
Oct 14, 2020
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: 12 additions & 12 deletions pandas/core/dtypes/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@

import numpy as np

from pandas._libs import lib, tslib, tslibs
from pandas._libs import lib, tslib
from pandas._libs.tslibs import (
NaT,
OutOfBoundsDatetime,
Period,
Timedelta,
Timestamp,
conversion,
iNaT,
ints_to_pydatetime,
ints_to_pytimedelta,
)
from pandas._libs.tslibs.timezones import tz_compare
from pandas._typing import ArrayLike, Dtype, DtypeObj
Expand Down Expand Up @@ -552,7 +554,7 @@ def maybe_promote(dtype, fill_value=np.nan):
dtype = np.dtype(np.object_)
else:
try:
fill_value = tslibs.Timestamp(fill_value).to_datetime64()
fill_value = Timestamp(fill_value).to_datetime64()
except (TypeError, ValueError):
dtype = np.dtype(np.object_)
elif issubclass(dtype.type, np.timedelta64):
Expand All @@ -565,7 +567,7 @@ def maybe_promote(dtype, fill_value=np.nan):
dtype = np.dtype(np.object_)
else:
try:
fv = tslibs.Timedelta(fill_value)
fv = Timedelta(fill_value)
except ValueError:
dtype = np.dtype(np.object_)
else:
Expand Down Expand Up @@ -738,8 +740,8 @@ def infer_dtype_from_scalar(val, pandas_dtype: bool = False) -> Tuple[DtypeObj,
dtype = np.dtype(object)

elif isinstance(val, (np.datetime64, datetime)):
val = tslibs.Timestamp(val)
if val is tslibs.NaT or val.tz is None:
val = Timestamp(val)
if val is NaT or val.tz is None:
dtype = np.dtype("M8[ns]")
else:
if pandas_dtype:
Expand All @@ -750,7 +752,7 @@ def infer_dtype_from_scalar(val, pandas_dtype: bool = False) -> Tuple[DtypeObj,
val = val.value

elif isinstance(val, (np.timedelta64, timedelta)):
val = tslibs.Timedelta(val).value
val = Timedelta(val).value
dtype = np.dtype("m8[ns]")

elif is_bool(val):
Expand Down Expand Up @@ -941,9 +943,9 @@ def conv(r, dtype):
if np.any(isna(r)):
pass
elif dtype == DT64NS_DTYPE:
r = tslibs.Timestamp(r)
r = Timestamp(r)
elif dtype == TD64NS_DTYPE:
r = tslibs.Timedelta(r)
r = Timedelta(r)
elif dtype == np.bool_:
# messy. non 0/1 integers do not get converted.
if is_integer(r) and r not in [0, 1]:
Expand Down Expand Up @@ -1006,7 +1008,7 @@ def astype_nansafe(arr, dtype, copy: bool = True, skipna: bool = False):

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

from pandas import DatetimeIndex

try:
Expand Down Expand Up @@ -1492,7 +1492,7 @@ def maybe_cast_to_datetime(value, dtype, errors: str = "raise"):
dtype = value.dtype

if dtype.kind == "M" and dtype != DT64NS_DTYPE:
value = tslibs.conversion.ensure_datetime64ns(value)
value = conversion.ensure_datetime64ns(value)

elif dtype.kind == "m" and dtype != TD64NS_DTYPE:
value = to_timedelta(value)
Expand Down
14 changes: 4 additions & 10 deletions pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,6 @@ def __repr__(self) -> str_type:

@staticmethod
def _hash_categories(categories, ordered: Ordered = True) -> int:
from pandas.core.dtypes.common import DT64NS_DTYPE, is_datetime64tz_dtype

from pandas.core.util.hashing import (
combine_hash_arrays,
hash_array,
Expand All @@ -430,9 +428,9 @@ def _hash_categories(categories, ordered: Ordered = True) -> int:
hashed = hash((tuple(categories), ordered))
return hashed

if is_datetime64tz_dtype(categories.dtype):
if DatetimeTZDtype.is_dtype(categories.dtype):
# Avoid future warning.
categories = categories.astype(DT64NS_DTYPE)
categories = categories.astype("datetime64[ns]")

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

def __new__(cls, subtype=None):
from pandas.core.dtypes.common import (
is_categorical_dtype,
is_string_dtype,
pandas_dtype,
)
from pandas.core.dtypes.common import is_string_dtype, pandas_dtype

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

if is_categorical_dtype(subtype) or is_string_dtype(subtype):
if CategoricalDtype.is_dtype(subtype) or is_string_dtype(subtype):
# GH 19016
msg = (
"category, object, and string subtypes are not supported "
Expand Down
5 changes: 1 addition & 4 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
)
from pandas.core.reshape.melt import melt
from pandas.core.series import Series
from pandas.core.sorting import get_group_index, lexsort_indexer, nargsort

from pandas.io.common import get_filepath_or_buffer
from pandas.io.formats import console, format as fmt
Expand Down Expand Up @@ -5251,8 +5252,6 @@ def duplicated(
"""
from pandas._libs.hashtable import SIZE_HINT_LIMIT, duplicated_int64

from pandas.core.sorting import get_group_index

if self.empty:
return self._constructor_sliced(dtype=bool)

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

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

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

by = by[0]
k = self._get_label_or_level_values(by, axis=axis)
Expand Down
16 changes: 10 additions & 6 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from pandas._config import config

from pandas._libs import lib
from pandas._libs.tslibs import Tick, Timestamp, to_offset
from pandas._libs.tslibs import Period, Tick, Timestamp, to_offset
from pandas._typing import (
Axis,
CompressionOptions,
Expand Down Expand Up @@ -86,17 +86,21 @@
from pandas.core.dtypes.missing import isna, notna

import pandas as pd
from pandas.core import missing, nanops
from pandas.core import indexing, missing, nanops
import pandas.core.algorithms as algos
from pandas.core.base import PandasObject, SelectionMixin
import pandas.core.common as com
from pandas.core.construction import create_series_with_explicit_dtype
from pandas.core.flags import Flags
from pandas.core.indexes import base as ibase
from pandas.core.indexes.api import Index, MultiIndex, RangeIndex, ensure_index
from pandas.core.indexes.datetimes import DatetimeIndex
from pandas.core.indexes.period import Period, PeriodIndex
import pandas.core.indexing as indexing
from pandas.core.indexes.api import (
DatetimeIndex,
Index,
MultiIndex,
PeriodIndex,
RangeIndex,
ensure_index,
)
from pandas.core.internals import BlockManager
from pandas.core.missing import find_valid_index
from pandas.core.ops import align_method_FRAME
Expand Down
9 changes: 3 additions & 6 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@
from pandas._libs import algos as libalgos, index as libindex, lib
import pandas._libs.join as libjoin
from pandas._libs.lib import is_datetime_array, no_default
from pandas._libs.tslibs import OutOfBoundsDatetime, Timestamp
from pandas._libs.tslibs.period import IncompatibleFrequency
from pandas._libs.tslibs import IncompatibleFrequency, OutOfBoundsDatetime, Timestamp
from pandas._libs.tslibs.timezones import tz_compare
from pandas._typing import AnyArrayLike, Dtype, DtypeObj, Label
from pandas.compat.numpy import function as nv
from pandas.errors import DuplicateLabelError, InvalidIndexError
from pandas.util._decorators import Appender, cache_readonly, doc

from pandas.core.dtypes import concat as _concat
from pandas.core.dtypes.cast import (
maybe_cast_to_integer_array,
validate_numeric_casting,
Expand Down Expand Up @@ -77,7 +75,7 @@
)
from pandas.core.dtypes.missing import array_equivalent, isna

from pandas.core import ops
from pandas.core import missing, ops
from pandas.core.accessor import CachedAccessor
import pandas.core.algorithms as algos
from pandas.core.arrays import Categorical, ExtensionArray
Expand All @@ -86,7 +84,6 @@
import pandas.core.common as com
from pandas.core.indexers import deprecate_ndim_indexing
from pandas.core.indexes.frozen import FrozenList
import pandas.core.missing as missing
from pandas.core.ops import get_op_result_name
from pandas.core.ops.invalid import make_invalid_op
from pandas.core.sorting import ensure_key_mapped, nargsort
Expand Down Expand Up @@ -4205,7 +4202,7 @@ def _concat(self, to_concat, name):
"""
to_concat = [x._values if isinstance(x, Index) else x for x in to_concat]

result = _concat.concat_compat(to_concat)
result = concat_compat(to_concat)
return Index(result, name=name)

def putmask(self, mask, value):
Expand Down
1 change: 0 additions & 1 deletion pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3093,7 +3093,6 @@ def get_locs(self, seq):
>>> mi.get_locs([[True, False, True], slice('e', 'f')]) # doctest: +SKIP
array([2], dtype=int64)
"""
from pandas.core.indexes.numeric import Int64Index

# must be lexsorted to at least as many levels
true_slices = [i for (i, s) in enumerate(com.is_true_slices(seq)) if s]
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

import numpy as np

from pandas._libs import NaT, algos as libalgos, lib, writers
import pandas._libs.internals as libinternals
from pandas._libs import NaT, algos as libalgos, internals as libinternals, lib, writers
from pandas._libs.internals import BlockPlacement
from pandas._libs.tslibs import conversion
from pandas._libs.tslibs.timezones import tz_compare
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

import numpy as np

from pandas._libs import Timedelta, hashtable as libhashtable, lib
import pandas._libs.join as libjoin
from pandas._libs import Timedelta, hashtable as libhashtable, join as libjoin, lib
from pandas._typing import ArrayLike, FrameOrSeries, FrameOrSeriesUnion
from pandas.errors import MergeError
from pandas.util._decorators import Appender, Substitution
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
remove_na_arraylike,
)

import pandas as pd
from pandas.core import algorithms, base, generic, nanops, ops
from pandas.core.accessor import CachedAccessor
from pandas.core.aggregation import aggregate, transform
Expand All @@ -76,6 +75,7 @@
from pandas.core.arrays.sparse import SparseAccessor
import pandas.core.common as com
from pandas.core.construction import (
array as pd_array,
create_series_with_explicit_dtype,
extract_array,
is_empty_data,
Expand Down Expand Up @@ -4193,7 +4193,7 @@ def f(x):
if len(mapped) and isinstance(mapped[0], Series):
# GH 25959 use pd.array instead of tolist
# so extension arrays can be used
return self._constructor_expanddim(pd.array(mapped), index=self.index)
return self._constructor_expanddim(pd_array(mapped), index=self.index)
else:
return self._constructor(mapped, index=self.index).__finalize__(
self, method="apply"
Expand Down
Loading