Skip to content

UPGRADE: Autoupdate pre-commit config #49428

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 25 commits into from
Nov 4, 2022
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
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ repos:
pass_filenames: true
require_serial: false
- repo: https://github.com/python/black
rev: 22.8.0
rev: 22.10.0
hooks:
- id: black
- repo: https://github.com/codespell-project/codespell
rev: v2.2.1
rev: v2.2.2
hooks:
- id: codespell
types_or: [python, rst, markdown]
- repo: https://github.com/MarcoGorelli/cython-lint
rev: v0.1.8
rev: v0.2.1
hooks:
- id: cython-lint
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down Expand Up @@ -60,15 +60,15 @@ repos:
- flake8-bugbear==22.7.1
- pandas-dev-flaker==0.5.0
- repo: https://github.com/pycqa/pylint
rev: v2.15.3
rev: v2.15.5
hooks:
- id: pylint
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort
- repo: https://github.com/asottile/pyupgrade
rev: v2.38.2
rev: v3.2.0
hooks:
- id: pyupgrade
args: [--py38-plus]
Expand All @@ -83,7 +83,7 @@ repos:
types: [text] # overwrite types: [rst]
types_or: [python, rst]
- repo: https://github.com/sphinx-contrib/sphinx-lint
rev: v0.6.1
rev: v0.6.7
hooks:
- id: sphinx-lint
- repo: https://github.com/asottile/yesqa
Expand Down
57 changes: 40 additions & 17 deletions pandas/_libs/algos.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,48 @@ class Infinity:
"""
Provide a positive Infinity comparison method for ranking.
"""
__lt__ = lambda self, other: False
__le__ = lambda self, other: isinstance(other, Infinity)
__eq__ = lambda self, other: isinstance(other, Infinity)
__ne__ = lambda self, other: not isinstance(other, Infinity)
__gt__ = lambda self, other: (not isinstance(other, Infinity) and
not missing.checknull(other))
__ge__ = lambda self, other: not missing.checknull(other)
def __lt__(self, other):
return False

def __le__(self, other):
return isinstance(other, Infinity)

def __eq__(self, other):
return isinstance(other, Infinity)

def __ne__(self, other):
return not isinstance(other, Infinity)

def __gt__(self, other):
return (not isinstance(other, Infinity) and
not missing.checknull(other))

def __ge__(self, other):
return not missing.checknull(other)


class NegInfinity:
"""
Provide a negative Infinity comparison method for ranking.
"""
__lt__ = lambda self, other: (not isinstance(other, NegInfinity) and
not missing.checknull(other))
__le__ = lambda self, other: not missing.checknull(other)
__eq__ = lambda self, other: isinstance(other, NegInfinity)
__ne__ = lambda self, other: not isinstance(other, NegInfinity)
__gt__ = lambda self, other: False
__ge__ = lambda self, other: isinstance(other, NegInfinity)
def __lt__(self, other):
return (not isinstance(other, NegInfinity) and
not missing.checknull(other))

def __le__(self, other):
return not missing.checknull(other)

def __eq__(self, other):
return isinstance(other, NegInfinity)

def __ne__(self, other):
return not isinstance(other, NegInfinity)

def __gt__(self, other):
return False

def __ge__(self, other):
return isinstance(other, NegInfinity)


@cython.wraparound(False)
Expand Down Expand Up @@ -321,7 +343,7 @@ def kth_smallest(numeric_t[::1] arr, Py_ssize_t k) -> numeric_t:
@cython.cdivision(True)
def nancorr(const float64_t[:, :] mat, bint cov=False, minp=None):
cdef:
Py_ssize_t i, j, xi, yi, N, K
Py_ssize_t i, xi, yi, N, K
bint minpv
float64_t[:, ::1] result
ndarray[uint8_t, ndim=2] mask
Expand Down Expand Up @@ -377,7 +399,7 @@ def nancorr(const float64_t[:, :] mat, bint cov=False, minp=None):
@cython.wraparound(False)
def nancorr_spearman(ndarray[float64_t, ndim=2] mat, Py_ssize_t minp=1) -> ndarray:
cdef:
Py_ssize_t i, j, xi, yi, N, K
Py_ssize_t i, xi, yi, N, K
ndarray[float64_t, ndim=2] result
ndarray[float64_t, ndim=2] ranked_mat
ndarray[float64_t, ndim=1] rankedx, rankedy
Expand Down Expand Up @@ -746,7 +768,8 @@ def is_monotonic(ndarray[numeric_object_t, ndim=1] arr, bint timelike):
n = len(arr)

if n == 1:
if arr[0] != arr[0] or (numeric_object_t is int64_t and timelike and arr[0] == NPY_NAT):
if arr[0] != arr[0] or (numeric_object_t is int64_t and timelike and
arr[0] == NPY_NAT):
# single value is NaN
return False, False, True
else:
Expand Down
46 changes: 31 additions & 15 deletions pandas/_libs/groupby.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def group_cumprod(
This method modifies the `out` parameter, rather than returning an object.
"""
cdef:
Py_ssize_t i, j, N, K, size
Py_ssize_t i, j, N, K
int64float_t val, na_val
int64float_t[:, ::1] accum
intp_t lab
Expand Down Expand Up @@ -356,7 +356,7 @@ def group_cumsum(
This method modifies the `out` parameter, rather than returning an object.
"""
cdef:
Py_ssize_t i, j, N, K, size
Py_ssize_t i, j, N, K
int64float_t val, y, t, na_val
int64float_t[:, ::1] accum, compensation
uint8_t[:, ::1] accum_mask
Expand Down Expand Up @@ -441,7 +441,7 @@ def group_shift_indexer(
int periods,
) -> None:
cdef:
Py_ssize_t N, i, j, ii, lab
Py_ssize_t N, i, ii, lab
int offset = 0, sign
int64_t idxer, idxer_slot
int64_t[::1] label_seen = np.zeros(ngroups, dtype=np.int64)
Expand Down Expand Up @@ -743,8 +743,11 @@ def group_sum(
# is otherwise the same as in _treat_as_na
if uses_mask:
isna_entry = mask[i, j]
elif (sum_t is float32_t or sum_t is float64_t
or sum_t is complex64_t or sum_t is complex64_t):
elif (
sum_t is float32_t
or sum_t is float64_t
or sum_t is complex64_t
):
# avoid warnings because of equality comparison
isna_entry = not val == val
elif sum_t is int64_t and is_datetimelike and val == NPY_NAT:
Expand All @@ -770,8 +773,11 @@ def group_sum(
# set a placeholder value in out[i, j].
if uses_mask:
result_mask[i, j] = True
elif (sum_t is float32_t or sum_t is float64_t
or sum_t is complex64_t or sum_t is complex64_t):
elif (
sum_t is float32_t
or sum_t is float64_t
or sum_t is complex64_t
):
out[i, j] = NAN
elif sum_t is int64_t:
out[i, j] = NPY_NAT
Expand Down Expand Up @@ -799,7 +805,7 @@ def group_prod(
"""
cdef:
Py_ssize_t i, j, N, K, lab, ncounts = len(counts)
int64float_t val, count
int64float_t val
int64float_t[:, ::1] prodx
int64_t[:, ::1] nobs
Py_ssize_t len_values = len(values), len_labels = len(labels)
Expand Down Expand Up @@ -872,7 +878,7 @@ def group_var(
floating[:, ::1] mean
int64_t[:, ::1] nobs
Py_ssize_t len_values = len(values), len_labels = len(labels)
bint isna_entry, uses_mask = not mask is None
bint isna_entry, uses_mask = mask is not None

assert min_count == -1, "'min_count' only used in sum and prod"

Expand Down Expand Up @@ -969,7 +975,7 @@ def group_mean(
mean_t[:, ::1] sumx, compensation
int64_t[:, ::1] nobs
Py_ssize_t len_values = len(values), len_labels = len(labels)
bint isna_entry, uses_mask = not mask is None
bint isna_entry, uses_mask = mask is not None

assert min_count == -1, "'min_count' only used in sum and prod"

Expand Down Expand Up @@ -1042,10 +1048,10 @@ def group_ohlc(
Only aggregates on axis=0
"""
cdef:
Py_ssize_t i, j, N, K, lab
Py_ssize_t i, N, K, lab
int64float_t val
uint8_t[::1] first_element_set
bint isna_entry, uses_mask = not mask is None
bint isna_entry, uses_mask = mask is not None

assert min_count == -1, "'min_count' only used in sum and prod"

Expand Down Expand Up @@ -1240,7 +1246,11 @@ cdef inline bint _treat_as_na(numeric_object_t val, bint is_datetimelike) nogil:
return False


cdef numeric_object_t _get_min_or_max(numeric_object_t val, bint compute_max, bint is_datetimelike):
cdef numeric_object_t _get_min_or_max(
numeric_object_t val,
bint compute_max,
bint is_datetimelike,
):
"""
Find either the min or the max supported by numeric_object_t; 'val' is a
placeholder to effectively make numeric_object_t an argument.
Expand Down Expand Up @@ -1366,7 +1376,10 @@ def group_last(
# set a placeholder value in out[i, j].
if uses_mask:
result_mask[i, j] = True
elif numeric_object_t is float32_t or numeric_object_t is float64_t:
elif (
numeric_object_t is float32_t
or numeric_object_t is float64_t
):
out[i, j] = NAN
elif numeric_object_t is int64_t:
# Per above, this is a placeholder in
Expand Down Expand Up @@ -1486,7 +1499,10 @@ def group_nth(
# it was initialized with np.empty. Also ensures
# we can downcast out if appropriate.
out[i, j] = 0
elif numeric_object_t is float32_t or numeric_object_t is float64_t:
elif (
numeric_object_t is float32_t
or numeric_object_t is float64_t
):
out[i, j] = NAN
elif numeric_object_t is int64_t:
# Per above, this is a placeholder in
Expand Down
12 changes: 9 additions & 3 deletions pandas/_libs/internals.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ cdef class BlockPlacement:
@property
def as_array(self) -> np.ndarray:
cdef:
Py_ssize_t start, stop, end, _
Py_ssize_t start, stop, _

if not self._has_array:
start, stop, step, _ = slice_get_indices_ex(self._as_slice)
Expand Down Expand Up @@ -259,7 +259,6 @@ cdef class BlockPlacement:
"""
cdef:
slice slc = self._ensure_has_slice()
slice new_slice
ndarray[intp_t, ndim=1] new_placement

if slc is not None and slc.step == 1:
Expand Down Expand Up @@ -678,7 +677,14 @@ cdef class BlockManager:
public list refs
public object parent

def __cinit__(self, blocks=None, axes=None, refs=None, parent=None, verify_integrity=True):
def __cinit__(
self,
blocks=None,
axes=None,
refs=None,
parent=None,
verify_integrity=True,
):
# None as defaults for unpickling GH#42345
if blocks is None:
# This adds 1-2 microseconds to DataFrame(np.array([]))
Expand Down
6 changes: 3 additions & 3 deletions pandas/_libs/join.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def left_join_indexer_unique(
cdef:
Py_ssize_t i, j, nleft, nright
ndarray[intp_t] indexer
numeric_object_t lval, rval
numeric_object_t rval

i = 0
j = 0
Expand Down Expand Up @@ -324,7 +324,7 @@ def left_join_indexer(ndarray[numeric_object_t] left, ndarray[numeric_object_t]
is non-unique (if both were unique we'd use left_join_indexer_unique).
"""
cdef:
Py_ssize_t i, j, k, nright, nleft, count
Py_ssize_t i, j, nright, nleft, count
numeric_object_t lval, rval
ndarray[intp_t] lindexer, rindexer
ndarray[numeric_object_t] result
Expand Down Expand Up @@ -434,7 +434,7 @@ def inner_join_indexer(ndarray[numeric_object_t] left, ndarray[numeric_object_t]
Both left and right are monotonic increasing but not necessarily unique.
"""
cdef:
Py_ssize_t i, j, k, nright, nleft, count
Py_ssize_t i, j, nright, nleft, count
numeric_object_t lval, rval
ndarray[intp_t] lindexer, rindexer
ndarray[numeric_object_t] result
Expand Down
Loading