Skip to content

CLN: update _simple_new usages #31089

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
Jan 18, 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
4 changes: 2 additions & 2 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def __new__(
ambiguous=ambiguous,
)

subarr = cls._simple_new(dtarr, name=name, freq=dtarr.freq, tz=dtarr.tz)
subarr = cls._simple_new(dtarr, name=name)
return subarr

@classmethod
Expand Down Expand Up @@ -1163,7 +1163,7 @@ def date_range(
closed=closed,
**kwargs,
)
return DatetimeIndex._simple_new(dtarr, tz=dtarr.tz, freq=dtarr.freq, name=name)
return DatetimeIndex._simple_new(dtarr, name=name)


def bdate_range(
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/indexes/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def __new__(
tdarr = TimedeltaArray._from_sequence(
data, freq=freq, unit=unit, dtype=dtype, copy=copy
)
return cls._simple_new(tdarr._data, freq=tdarr.freq, name=name)
return cls._simple_new(tdarr, name=name)

@classmethod
def _simple_new(cls, values, name=None, freq=None, dtype=_TD_DTYPE):
Expand Down Expand Up @@ -507,4 +507,4 @@ def timedelta_range(

freq, freq_infer = dtl.maybe_infer_freq(freq)
tdarr = TimedeltaArray._generate_range(start, end, periods, freq, closed=closed)
return TimedeltaIndex._simple_new(tdarr._data, freq=tdarr.freq, name=name)
return TimedeltaIndex._simple_new(tdarr, name=name)
10 changes: 6 additions & 4 deletions pandas/core/tools/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@
)
from pandas.core.dtypes.missing import notna

from pandas.arrays import IntegerArray
from pandas.arrays import DatetimeArray, IntegerArray
from pandas.core import algorithms
from pandas.core.algorithms import unique
from pandas.core.arrays.datetimes import tz_to_dtype

# ---------------------------------------------------------------------
# types used in annotations
Expand Down Expand Up @@ -282,7 +283,6 @@ def _convert_listlike_datetimes(
Index-like of parsed dates
"""
from pandas import DatetimeIndex
from pandas.core.arrays import DatetimeArray
from pandas.core.arrays.datetimes import (
maybe_convert_dtype,
objects_to_datetime64ns,
Expand Down Expand Up @@ -427,7 +427,8 @@ def _convert_listlike_datetimes(
# datetime objects are found without passing `utc=True`
try:
values, tz = conversion.datetime_to_datetime64(arg)
return DatetimeIndex._simple_new(values, name=name, tz=tz)
dta = DatetimeArray(values, dtype=tz_to_dtype(tz))
return DatetimeIndex._simple_new(dta, name=name)
except (ValueError, TypeError):
raise e

Expand All @@ -447,7 +448,8 @@ def _convert_listlike_datetimes(
if tz_parsed is not None:
# We can take a shortcut since the datetime64 numpy array
# is in UTC
return DatetimeIndex._simple_new(result, name=name, tz=tz_parsed)
dta = DatetimeArray(result, dtype=tz_to_dtype(tz_parsed))
return DatetimeIndex._simple_new(dta, name=name)

utc = tz == "utc"
return _box_as_indexlike(result, utc=utc, name=name)
Expand Down
8 changes: 5 additions & 3 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
concat,
isna,
)
from pandas.core.arrays.categorical import Categorical
from pandas.core.arrays import Categorical, DatetimeArray, PeriodArray
import pandas.core.common as com
from pandas.core.computation.pytables import PyTablesExpr, maybe_expression
from pandas.core.indexes.api import ensure_index
Expand Down Expand Up @@ -2656,7 +2656,8 @@ def _get_index_factory(self, klass):

def f(values, freq=None, tz=None):
# data are already in UTC, localize and convert if tz present
result = DatetimeIndex._simple_new(values.values, name=None, freq=freq)
dta = DatetimeArray._simple_new(values.values, freq=freq)
result = DatetimeIndex._simple_new(dta, name=None)
if tz is not None:
result = result.tz_localize("UTC").tz_convert(tz)
return result
Expand All @@ -2665,7 +2666,8 @@ def f(values, freq=None, tz=None):
elif klass == PeriodIndex:

def f(values, freq=None, tz=None):
return PeriodIndex._simple_new(values, name=None, freq=freq)
parr = PeriodArray._simple_new(values, freq=freq)
return PeriodIndex._simple_new(parr, name=None)

return f

Expand Down