Skip to content

CLN: annotate ndim, is_monotonic_decreasing, has_duplicates, is_, nlevels #29561

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 5 commits into from
Nov 12, 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
2 changes: 1 addition & 1 deletion pandas/_libs/indexing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cdef class _NDFrameIndexerBase:
self._ndim = None

@property
def ndim(self):
def ndim(self) -> int:
# Delay `ndim` instantiation until required as reading it
# from `obj` isn't entirely cheap.
ndim = self._ndim
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ def transpose(self, *args, **kwargs):
)

@property
def _is_homogeneous_type(self):
def _is_homogeneous_type(self) -> bool:
"""
Whether the object has a single dtype.

Expand All @@ -711,7 +711,7 @@ def shape(self):
return self._values.shape

@property
def ndim(self):
def ndim(self) -> int:
"""
Number of dimensions of the underlying data, by definition 1.
"""
Expand Down Expand Up @@ -1467,7 +1467,7 @@ def is_monotonic(self):
is_monotonic_increasing = is_monotonic

@property
def is_monotonic_decreasing(self):
def is_monotonic_decreasing(self) -> bool:
"""
Return boolean if values in the object are
monotonic_decreasing.
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/computation/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def name(self):
return self._name

@property
def ndim(self):
def ndim(self) -> int:
return self._value.ndim


Expand Down
2 changes: 1 addition & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ def axes(self):
return [self._get_axis(a) for a in self._AXIS_ORDERS]

@property
def ndim(self):
def ndim(self) -> int:
"""
Return an int representing the number of axes / array dimensions.

Expand Down
8 changes: 4 additions & 4 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ def _update_inplace(self, result, **kwargs):
# guard when called from IndexOpsMixin
raise TypeError("Index can't be updated inplace")

def is_(self, other):
def is_(self, other) -> bool:
"""
More flexible, faster check like ``is`` but that works through views.

Expand Down Expand Up @@ -1452,7 +1452,7 @@ def rename(self, name, inplace=False):
# Level-Centric Methods

@property
def nlevels(self):
def nlevels(self) -> int:
"""
Number of levels.
"""
Expand Down Expand Up @@ -1677,7 +1677,7 @@ def is_monotonic_increasing(self):
return self._engine.is_monotonic_increasing

@property
def is_monotonic_decreasing(self):
def is_monotonic_decreasing(self) -> bool:
"""
Return if the index is monotonic decreasing (only equal or
decreasing) values.
Expand Down Expand Up @@ -1735,7 +1735,7 @@ def is_unique(self):
return self._engine.is_unique

@property
def has_duplicates(self):
def has_duplicates(self) -> bool:
return not self.is_unique

def is_boolean(self):
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ def is_monotonic_increasing(self):
return self._engine.is_monotonic_increasing

@property
def is_monotonic_decreasing(self):
def is_monotonic_decreasing(self) -> bool:
return self._engine.is_monotonic_decreasing

@Appender(_index_shared_docs["index_unique"] % _index_doc_kwargs)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ def is_monotonic_increasing(self):
return self._engine.is_monotonic_increasing

@cache_readonly
def is_monotonic_decreasing(self):
def is_monotonic_decreasing(self) -> bool:
"""
Return True if the IntervalIndex is monotonic decreasing (only equal or
decreasing values), else False
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ def array(self):
raise ValueError(msg)

@property
def _is_homogeneous_type(self):
def _is_homogeneous_type(self) -> bool:
"""Whether the levels of a MultiIndex all have the same dtype.

This looks at the dtypes of the levels.
Expand Down Expand Up @@ -1427,7 +1427,7 @@ def is_monotonic_increasing(self):
return Index(self.values).is_monotonic

@cache_readonly
def is_monotonic_decreasing(self):
def is_monotonic_decreasing(self) -> bool:
"""
return if the index is monotonic decreasing (only equal or
decreasing) values.
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/indexes/range.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,11 @@ def is_monotonic_increasing(self):
return self._range.step > 0 or len(self) <= 1

@cache_readonly
def is_monotonic_decreasing(self):
def is_monotonic_decreasing(self) -> bool:
return self._range.step < 0 or len(self) <= 1

@property
def has_duplicates(self):
def has_duplicates(self) -> bool:
return False

def __contains__(self, key: Union[int, np.integer]) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def shape(self):
return tuple(len(ax) for ax in self.axes)

@property
def ndim(self):
def ndim(self) -> int:
return len(self.axes)

def set_axis(self, axis, new_labels):
Expand Down