Skip to content

Commit 2115bf3

Browse files
jbrockmendeltopper-123
authored andcommitted
small cleanups (#26874)
Thanks, @jbrockmendel
1 parent 430f0fd commit 2115bf3

File tree

9 files changed

+17
-16
lines changed

9 files changed

+17
-16
lines changed

pandas/core/arrays/datetimelike.py

-4
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,6 @@ def __array__(self, dtype=None):
401401
return np.array(list(self), dtype=object)
402402
return self._data
403403

404-
@property
405-
def shape(self):
406-
return (len(self),)
407-
408404
@property
409405
def size(self) -> int:
410406
"""The number of elements in this array."""

pandas/core/arrays/datetimes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ class DatetimeArray(dtl.DatetimeLikeArrayMixin,
265265
'normalize', 'strftime', 'round', 'floor',
266266
'ceil', 'month_name', 'day_name']
267267

268-
# Needed so that Timestamp.__richcmp__(DateTimeArray) operates pointwise
269-
ndim = 1
268+
# ndim is inherited from ExtensionArray, must exist to ensure
269+
# Timestamp.__richcmp__(DateTimeArray) operates pointwise
270270

271271
# ensure that operations with numpy arrays defer to our implementation
272272
__array_priority__ = 1000

pandas/core/dtypes/concat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def is_nonempty(x):
132132
_contains_period = any(typ.startswith('period') for typ in typs)
133133

134134
if 'category' in typs:
135-
# this must be priort to _concat_datetime,
135+
# this must be prior to _concat_datetime,
136136
# to support Categorical + datetime-like
137137
return _concat_categorical(to_concat, axis=axis)
138138

pandas/core/internals/blocks.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
Categorical, DatetimeArray, ExtensionArray, PandasDtype, TimedeltaArray)
3737
from pandas.core.base import PandasObject
3838
import pandas.core.common as com
39-
from pandas.core.indexes.datetimes import DatetimeIndex
4039
from pandas.core.indexing import check_setitem_lengths
4140
from pandas.core.internals.arrays import extract_array
4241
import pandas.core.missing as missing
@@ -2091,7 +2090,7 @@ def _astype(self, dtype, **kwargs):
20912090
if is_datetime64tz_dtype(dtype):
20922091
values = self.values
20932092
if getattr(values, 'tz', None) is None:
2094-
values = DatetimeIndex(values).tz_localize('UTC')
2093+
values = DatetimeArray(values).tz_localize('UTC')
20952094
values = values.tz_convert(dtype.tz)
20962095
return self.make_block(values)
20972096

@@ -2420,7 +2419,7 @@ def setitem(self, indexer, value):
24202419
except (ValueError, TypeError):
24212420
newb = make_block(self.values.astype(object),
24222421
placement=self.mgr_locs,
2423-
klass=ObjectBlock,)
2422+
klass=ObjectBlock)
24242423
return newb.setitem(indexer, value)
24252424

24262425
def equals(self, other):

pandas/core/internals/construction.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ def init_ndarray(values, index, columns, dtype=None, copy=False):
131131
index, columns = _get_axes(len(values), 1, index, columns)
132132
return arrays_to_mgr([values], columns, index, columns,
133133
dtype=dtype)
134-
elif (is_datetime64tz_dtype(values) or
135-
is_extension_array_dtype(values)):
134+
elif is_extension_array_dtype(values):
136135
# GH#19157
137136
if columns is None:
138137
columns = [0]

pandas/core/internals/managers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
maybe_promote)
1616
from pandas.core.dtypes.common import (
1717
_NS_DTYPE, is_datetimelike_v_numeric, is_extension_array_dtype,
18-
is_extension_type, is_list_like, is_numeric_v_string_like, is_scalar)
18+
is_extension_type, is_list_like, is_numeric_v_string_like, is_scalar,
19+
is_sparse)
1920
import pandas.core.dtypes.concat as _concat
2021
from pandas.core.dtypes.dtypes import ExtensionDtype
2122
from pandas.core.dtypes.generic import ABCExtensionArray, ABCSeries
@@ -770,7 +771,6 @@ def _interleave(self):
770771
Return ndarray from blocks with specified item order
771772
Items must be contained in the blocks
772773
"""
773-
from pandas.core.dtypes.common import is_sparse
774774
dtype = _interleaved_dtype(self.blocks)
775775

776776
# TODO: https://github.com/pandas-dev/pandas/issues/22791

pandas/io/formats/format.py

+4
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ def _chk_truncate(self):
191191
series = concat((series.iloc[:row_num],
192192
series.iloc[-row_num:]))
193193
self.tr_row_num = row_num
194+
else:
195+
self.tr_row_num = None
194196
self.tr_series = series
195197
self.truncate_v = truncate_v
196198

@@ -499,6 +501,8 @@ def _chk_truncate(self):
499501
frame = concat((frame.iloc[:row_num, :],
500502
frame.iloc[-row_num:, :]))
501503
self.tr_row_num = row_num
504+
else:
505+
self.tr_row_num = None
502506

503507
self.tr_frame = frame
504508
self.truncate_h = truncate_h

pandas/tests/frame/test_repr_info.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -511,9 +511,11 @@ def test_repr_categorical_dates_periods(self):
511511
3 2011-01-01 12:00:00-05:00 2011-04
512512
4 2011-01-01 13:00:00-05:00 2011-05"""
513513

514-
df = DataFrame({'dt': Categorical(dt), 'p': Categorical(p)})
515514
assert repr(df) == exp
516515

516+
df2 = DataFrame({'dt': Categorical(dt), 'p': Categorical(p)})
517+
assert repr(df2) == exp
518+
517519
@pytest.mark.parametrize('arg', [np.datetime64, np.timedelta64])
518520
@pytest.mark.parametrize('box, expected', [
519521
[Series, '0 NaT\ndtype: object'],

pandas/tests/series/test_api.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,8 @@ def test_copy(self):
361361
assert np.isnan(s2[0])
362362
assert np.isnan(s[0])
363363

364-
# GH 11794
364+
def test_copy_tzaware(self):
365+
# GH#11794
365366
# copy of tz-aware
366367
expected = Series([Timestamp('2012/01/01', tz='UTC')])
367368
expected2 = Series([Timestamp('1999/01/01', tz='UTC')])

0 commit comments

Comments
 (0)