From b079f75feb97d65c97f8f171d63a2c7bf5b7c568 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 10 Dec 2019 15:13:17 -0800 Subject: [PATCH 1/3] CLN: remove redundant Index checks --- pandas/core/indexes/base.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 1587d97ffb52c..60637e08dedfb 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -732,24 +732,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 ) From de8f811067bb5bd6b882d40310994972a1696804 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 10 Dec 2019 17:45:44 -0800 Subject: [PATCH 2/3] fixup unused import --- pandas/core/index.py | 7 +++++++ pandas/core/indexes/base.py | 1 - pandas/core/indexes/period.py | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pandas/core/index.py b/pandas/core/index.py index 84b37b8bd659d..c7c6f52f18a11 100644 --- a/pandas/core/index.py +++ b/pandas/core/index.py @@ -19,3 +19,10 @@ get_objs_combined_axis, ) from pandas.core.indexes.multi import _sparsify # noqa:F401 + +import warnings +warnings.warn( + "pandas.core.index is deprecated and will be removed in a future version. " + "Use pandas.core.indexes.api instead.", + FutureWarning, +) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 60637e08dedfb..803c29c327b8e 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -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 ( diff --git a/pandas/core/indexes/period.py b/pandas/core/indexes/period.py index d63de10d92921..003b9dd8d0eb4 100644 --- a/pandas/core/indexes/period.py +++ b/pandas/core/indexes/period.py @@ -261,6 +261,7 @@ def _simple_new(cls, values, name=None, freq=None, **kwargs): # TODO: raising on floats is tested, but maybe not useful. # Should the callers know not to pass floats? # At the very least, I think we can ensure that lists aren't passed. + assert not isinstance(values, list) if isinstance(values, list): values = np.asarray(values) if is_float_dtype(values): From 21d0d6a47a9ebc80fb99cf8d122d0d09917e6632 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 10 Dec 2019 19:22:12 -0800 Subject: [PATCH 3/3] revert unwanted changes --- pandas/core/index.py | 7 ------- pandas/core/indexes/period.py | 1 - 2 files changed, 8 deletions(-) diff --git a/pandas/core/index.py b/pandas/core/index.py index c7c6f52f18a11..84b37b8bd659d 100644 --- a/pandas/core/index.py +++ b/pandas/core/index.py @@ -19,10 +19,3 @@ get_objs_combined_axis, ) from pandas.core.indexes.multi import _sparsify # noqa:F401 - -import warnings -warnings.warn( - "pandas.core.index is deprecated and will be removed in a future version. " - "Use pandas.core.indexes.api instead.", - FutureWarning, -) diff --git a/pandas/core/indexes/period.py b/pandas/core/indexes/period.py index 003b9dd8d0eb4..d63de10d92921 100644 --- a/pandas/core/indexes/period.py +++ b/pandas/core/indexes/period.py @@ -261,7 +261,6 @@ def _simple_new(cls, values, name=None, freq=None, **kwargs): # TODO: raising on floats is tested, but maybe not useful. # Should the callers know not to pass floats? # At the very least, I think we can ensure that lists aren't passed. - assert not isinstance(values, list) if isinstance(values, list): values = np.asarray(values) if is_float_dtype(values):