Skip to content

CLN: remove redundant Index checks #30195

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
Dec 11, 2019
Merged
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
14 changes: 0 additions & 14 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
is_signed_integer_dtype,
is_timedelta64_dtype,
is_unsigned_integer_dtype,
pandas_dtype,
)
from pandas.core.dtypes.concat import concat_compat
from pandas.core.dtypes.generic import (
Expand Down Expand Up @@ -732,24 +731,11 @@ def astype(self, dtype, copy=True):
from .category import CategoricalIndex

return CategoricalIndex(self.values, name=self.name, dtype=dtype, copy=copy)
elif is_datetime64tz_dtype(dtype):
# TODO(GH-24559): Remove this block, use the following elif.
# avoid FutureWarning from DatetimeIndex constructor.
from pandas import DatetimeIndex

tz = pandas_dtype(dtype).tz
return DatetimeIndex(np.asarray(self)).tz_localize("UTC").tz_convert(tz)

elif is_extension_array_dtype(dtype):
return Index(np.asarray(self), dtype=dtype, copy=copy)

try:
if is_datetime64tz_dtype(dtype):
from pandas import DatetimeIndex

return DatetimeIndex(
self.values, name=self.name, dtype=dtype, copy=copy
)
return Index(
self.values.astype(dtype, copy=copy), name=self.name, dtype=dtype
)
Expand Down