diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index b0c91543dabac..ebf1f692ccde6 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -401,10 +401,6 @@ def __array__(self, dtype=None): return np.array(list(self), dtype=object) return self._data - @property - def shape(self): - return (len(self),) - @property def size(self) -> int: """The number of elements in this array.""" diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 47aef3c84c9f7..d415dbbdaf0a3 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -265,8 +265,8 @@ class DatetimeArray(dtl.DatetimeLikeArrayMixin, 'normalize', 'strftime', 'round', 'floor', 'ceil', 'month_name', 'day_name'] - # Needed so that Timestamp.__richcmp__(DateTimeArray) operates pointwise - ndim = 1 + # ndim is inherited from ExtensionArray, must exist to ensure + # Timestamp.__richcmp__(DateTimeArray) operates pointwise # ensure that operations with numpy arrays defer to our implementation __array_priority__ = 1000 diff --git a/pandas/core/dtypes/concat.py b/pandas/core/dtypes/concat.py index e2c6fba322be0..a01ba7fc94f22 100644 --- a/pandas/core/dtypes/concat.py +++ b/pandas/core/dtypes/concat.py @@ -132,7 +132,7 @@ def is_nonempty(x): _contains_period = any(typ.startswith('period') for typ in typs) if 'category' in typs: - # this must be priort to _concat_datetime, + # this must be prior to _concat_datetime, # to support Categorical + datetime-like return _concat_categorical(to_concat, axis=axis) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index f9178959d8272..4cc6c86417b3b 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -36,7 +36,6 @@ Categorical, DatetimeArray, ExtensionArray, PandasDtype, TimedeltaArray) from pandas.core.base import PandasObject import pandas.core.common as com -from pandas.core.indexes.datetimes import DatetimeIndex from pandas.core.indexing import check_setitem_lengths from pandas.core.internals.arrays import extract_array import pandas.core.missing as missing @@ -2091,7 +2090,7 @@ def _astype(self, dtype, **kwargs): if is_datetime64tz_dtype(dtype): values = self.values if getattr(values, 'tz', None) is None: - values = DatetimeIndex(values).tz_localize('UTC') + values = DatetimeArray(values).tz_localize('UTC') values = values.tz_convert(dtype.tz) return self.make_block(values) @@ -2420,7 +2419,7 @@ def setitem(self, indexer, value): except (ValueError, TypeError): newb = make_block(self.values.astype(object), placement=self.mgr_locs, - klass=ObjectBlock,) + klass=ObjectBlock) return newb.setitem(indexer, value) def equals(self, other): diff --git a/pandas/core/internals/construction.py b/pandas/core/internals/construction.py index 863b9f7fb16d7..2616f0aa97d0d 100644 --- a/pandas/core/internals/construction.py +++ b/pandas/core/internals/construction.py @@ -131,8 +131,7 @@ def init_ndarray(values, index, columns, dtype=None, copy=False): index, columns = _get_axes(len(values), 1, index, columns) return arrays_to_mgr([values], columns, index, columns, dtype=dtype) - elif (is_datetime64tz_dtype(values) or - is_extension_array_dtype(values)): + elif is_extension_array_dtype(values): # GH#19157 if columns is None: columns = [0] diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index 6f0e8a909d36f..a1e5468e2f871 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -15,7 +15,8 @@ maybe_promote) from pandas.core.dtypes.common import ( _NS_DTYPE, is_datetimelike_v_numeric, is_extension_array_dtype, - is_extension_type, is_list_like, is_numeric_v_string_like, is_scalar) + is_extension_type, is_list_like, is_numeric_v_string_like, is_scalar, + is_sparse) import pandas.core.dtypes.concat as _concat from pandas.core.dtypes.dtypes import ExtensionDtype from pandas.core.dtypes.generic import ABCExtensionArray, ABCSeries @@ -770,7 +771,6 @@ def _interleave(self): Return ndarray from blocks with specified item order Items must be contained in the blocks """ - from pandas.core.dtypes.common import is_sparse dtype = _interleaved_dtype(self.blocks) # TODO: https://github.com/pandas-dev/pandas/issues/22791 diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index f632bc13a5b24..8655fb05f34e2 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -191,6 +191,8 @@ def _chk_truncate(self): series = concat((series.iloc[:row_num], series.iloc[-row_num:])) self.tr_row_num = row_num + else: + self.tr_row_num = None self.tr_series = series self.truncate_v = truncate_v @@ -499,6 +501,8 @@ def _chk_truncate(self): frame = concat((frame.iloc[:row_num, :], frame.iloc[-row_num:, :])) self.tr_row_num = row_num + else: + self.tr_row_num = None self.tr_frame = frame self.truncate_h = truncate_h diff --git a/pandas/tests/frame/test_repr_info.py b/pandas/tests/frame/test_repr_info.py index 32594c856a236..24dba8cb964cc 100644 --- a/pandas/tests/frame/test_repr_info.py +++ b/pandas/tests/frame/test_repr_info.py @@ -511,9 +511,11 @@ def test_repr_categorical_dates_periods(self): 3 2011-01-01 12:00:00-05:00 2011-04 4 2011-01-01 13:00:00-05:00 2011-05""" - df = DataFrame({'dt': Categorical(dt), 'p': Categorical(p)}) assert repr(df) == exp + df2 = DataFrame({'dt': Categorical(dt), 'p': Categorical(p)}) + assert repr(df2) == exp + @pytest.mark.parametrize('arg', [np.datetime64, np.timedelta64]) @pytest.mark.parametrize('box, expected', [ [Series, '0 NaT\ndtype: object'], diff --git a/pandas/tests/series/test_api.py b/pandas/tests/series/test_api.py index 9b4f1f5fd0fe5..6c577304d5ef4 100644 --- a/pandas/tests/series/test_api.py +++ b/pandas/tests/series/test_api.py @@ -361,7 +361,8 @@ def test_copy(self): assert np.isnan(s2[0]) assert np.isnan(s[0]) - # GH 11794 + def test_copy_tzaware(self): + # GH#11794 # copy of tz-aware expected = Series([Timestamp('2012/01/01', tz='UTC')]) expected2 = Series([Timestamp('1999/01/01', tz='UTC')])