Skip to content

Commit

Permalink
small cleanups (#26874)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and topper-123 committed Jun 16, 2019
1 parent 430f0fd commit 2115bf3
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 16 deletions.
4 changes: 0 additions & 4 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/dtypes/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 2 additions & 3 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/internals/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/frame/test_repr_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/series/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')])
Expand Down

0 comments on commit 2115bf3

Please sign in to comment.