Skip to content

CLN: follow-ups #29600

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 6 commits into from
Nov 14, 2019
Merged
Show file tree
Hide file tree
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
29 changes: 12 additions & 17 deletions pandas/_libs/reduction.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,9 @@ cdef class Reducer:
else:

# we passed a series-like
if hasattr(dummy, 'values'):

typ = type(dummy)
index = getattr(dummy, 'index', None)
dummy = dummy.values
typ = type(dummy)
index = dummy.index
dummy = dummy.values

if dummy.dtype != self.arr.dtype:
raise ValueError('Dummy array must be same dtype')
Expand All @@ -99,10 +97,10 @@ cdef class Reducer:
cdef:
char* dummy_buf
ndarray arr, result, chunk
Py_ssize_t i, incr
Py_ssize_t i
flatiter it
bint has_labels
object res, name, labels, index
object res, name, labels
object cached_typ = None

arr = self.arr
Expand All @@ -112,7 +110,6 @@ cdef class Reducer:
labels = self.labels
has_labels = labels is not None
has_index = self.index is not None
incr = self.increment

result = np.empty(self.nresults, dtype='O')
it = <flatiter>PyArray_IterNew(result)
Expand Down Expand Up @@ -193,10 +190,10 @@ cdef class _BaseGrouper:
return values, index

cdef inline _update_cached_objs(self, object cached_typ, object cached_ityp,
Slider islider, Slider vslider, object name):
Slider islider, Slider vslider):
if cached_typ is None:
cached_ityp = self.ityp(islider.buf)
cached_typ = self.typ(vslider.buf, index=cached_ityp, name=name)
cached_typ = self.typ(vslider.buf, index=cached_ityp, name=self.name)
else:
# See the comment in indexes/base.py about _index_data.
# We need this for EA-backed indexes that have a reference
Expand All @@ -205,7 +202,7 @@ cdef class _BaseGrouper:
cached_ityp._engine.clear_mapping()
object.__setattr__(cached_typ._data._block, 'values', vslider.buf)
object.__setattr__(cached_typ, '_index', cached_ityp)
object.__setattr__(cached_typ, 'name', name)
object.__setattr__(cached_typ, 'name', self.name)

return cached_typ, cached_ityp

Expand Down Expand Up @@ -254,7 +251,7 @@ cdef class SeriesBinGrouper(_BaseGrouper):
object res
bint initialized = 0
Slider vslider, islider
object name, cached_typ = None, cached_ityp = None
object cached_typ = None, cached_ityp = None

counts = np.zeros(self.ngroups, dtype=np.int64)

Expand All @@ -268,7 +265,6 @@ cdef class SeriesBinGrouper(_BaseGrouper):

group_size = 0
n = len(self.arr)
name = self.name

vslider = Slider(self.arr, self.dummy_arr)
islider = Slider(self.index, self.dummy_index)
Expand All @@ -283,7 +279,7 @@ cdef class SeriesBinGrouper(_BaseGrouper):
vslider.set_length(group_size)

cached_typ, cached_ityp = self._update_cached_objs(
cached_typ, cached_ityp, islider, vslider, name)
cached_typ, cached_ityp, islider, vslider)

cached_ityp._engine.clear_mapping()
res = self.f(cached_typ)
Expand Down Expand Up @@ -356,13 +352,12 @@ cdef class SeriesGrouper(_BaseGrouper):
object res
bint initialized = 0
Slider vslider, islider
object name, cached_typ = None, cached_ityp = None
object cached_typ = None, cached_ityp = None

labels = self.labels
counts = np.zeros(self.ngroups, dtype=np.int64)
group_size = 0
n = len(self.arr)
name = self.name

vslider = Slider(self.arr, self.dummy_arr)
islider = Slider(self.index, self.dummy_index)
Expand All @@ -386,7 +381,7 @@ cdef class SeriesGrouper(_BaseGrouper):
vslider.set_length(group_size)

cached_typ, cached_ityp = self._update_cached_objs(
cached_typ, cached_ityp, islider, vslider, name)
cached_typ, cached_ityp, islider, vslider)

cached_ityp._engine.clear_mapping()
res = self.f(cached_typ)
Expand Down
12 changes: 6 additions & 6 deletions pandas/_libs/tslibs/c_timestamp.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ cdef class _Timestamp(datetime):
"""
return np.datetime64(self.value, 'ns')

def to_numpy(self, dtype=None, copy=False):
def to_numpy(self, dtype=None, copy=False) -> np.datetime64:
"""
Convert the Timestamp to a NumPy datetime64.

Expand Down Expand Up @@ -369,18 +369,18 @@ cdef class _Timestamp(datetime):
return out[0]

@property
def _repr_base(self):
def _repr_base(self) -> str:
return '{date} {time}'.format(date=self._date_repr,
time=self._time_repr)

@property
def _date_repr(self):
def _date_repr(self) -> str:
# Ideal here would be self.strftime("%Y-%m-%d"), but
# the datetime strftime() methods require year >= 1900
return '%d-%.2d-%.2d' % (self.year, self.month, self.day)

@property
def _time_repr(self):
def _time_repr(self) -> str:
result = '%.2d:%.2d:%.2d' % (self.hour, self.minute, self.second)

if self.nanosecond != 0:
Expand All @@ -391,7 +391,7 @@ cdef class _Timestamp(datetime):
return result

@property
def _short_repr(self):
def _short_repr(self) -> str:
# format a Timestamp with only _date_repr if possible
# otherwise _repr_base
if (self.hour == 0 and
Expand All @@ -403,7 +403,7 @@ cdef class _Timestamp(datetime):
return self._repr_base

@property
def asm8(self):
def asm8(self) -> np.datetime64:
"""
Return numpy datetime64 format in nanoseconds.
"""
Expand Down
8 changes: 4 additions & 4 deletions pandas/_libs/tslibs/nattype.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,16 @@ cdef class _NaT(datetime):
return NotImplemented

@property
def asm8(self):
def asm8(self) -> np.datetime64:
return np.datetime64(NPY_NAT, 'ns')

def to_datetime64(self):
def to_datetime64(self) -> np.datetime64:
"""
Return a numpy.datetime64 object with 'ns' precision.
"""
return np.datetime64('NaT', 'ns')

def to_numpy(self, dtype=None, copy=False):
def to_numpy(self, dtype=None, copy=False) -> np.datetime64:
"""
Convert the Timestamp to a NumPy datetime64.

Expand All @@ -265,7 +265,7 @@ cdef class _NaT(datetime):
def __str__(self) -> str:
return 'NaT'

def isoformat(self, sep='T'):
def isoformat(self, sep='T') -> str:
# This allows Timestamp(ts.isoformat()) to always correctly roundtrip.
return 'NaT'

Expand Down
16 changes: 8 additions & 8 deletions pandas/_libs/tslibs/timedeltas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -841,15 +841,15 @@ cdef class _Timedelta(timedelta):
"""
return timedelta(microseconds=int(self.value) / 1000)

def to_timedelta64(self):
def to_timedelta64(self) -> np.timedelta64:
"""
Return a numpy.timedelta64 object with 'ns' precision.
"""
return np.timedelta64(self.value, 'ns')

def to_numpy(self, dtype=None, copy=False):
def to_numpy(self, dtype=None, copy=False) -> np.timedelta64:
"""
Convert the Timestamp to a NumPy timedelta64.
Convert the Timedelta to a NumPy timedelta64.

.. versionadded:: 0.25.0

Expand Down Expand Up @@ -920,7 +920,7 @@ cdef class _Timedelta(timedelta):
return self.value

@property
def asm8(self):
def asm8(self) -> np.timedelta64:
"""
Return a numpy timedelta64 array scalar view.

Expand Down Expand Up @@ -955,7 +955,7 @@ cdef class _Timedelta(timedelta):
return np.int64(self.value).view('m8[ns]')

@property
def resolution_string(self):
def resolution_string(self) -> str:
"""
Return a string representing the lowest timedelta resolution.

Expand Down Expand Up @@ -1095,7 +1095,7 @@ cdef class _Timedelta(timedelta):
self._ensure_components()
return self._ns

def _repr_base(self, format=None):
def _repr_base(self, format=None) -> str:
"""

Parameters
Expand Down Expand Up @@ -1148,10 +1148,10 @@ cdef class _Timedelta(timedelta):
def __str__(self) -> str:
return self._repr_base(format='long')

def __bool__(self):
def __bool__(self) -> bool:
return self.value != 0

def isoformat(self):
def isoformat(self) -> str:
"""
Format Timedelta as ISO 8601 Duration like
``P[n]Y[n]M[n]DT[n]H[n]M[n]S``, where the ``[n]`` s are replaced by the
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/groupby/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,8 +830,7 @@ def agg_series(self, obj: Series, func):
assert self.ngroups != 0

if is_extension_array_dtype(obj.dtype):
# pre-empty SeriesBinGrouper from raising TypeError
# TODO: watch out, this can return None
# pre-empt SeriesBinGrouper from raising TypeError
return self._aggregate_series_pure_python(obj, func)

dummy = obj[:0]
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,8 @@ def __init__(
):
_left = _validate_operand(left)
_right = _validate_operand(right)
self.left = self.orig_left = _validate_operand(_left) # type: "DataFrame"
self.right = self.orig_right = _validate_operand(_right) # type: "DataFrame"
self.left = self.orig_left = _left
self.right = self.orig_right = _right
self.how = how
self.axis = axis

Expand Down