-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
CLN: General cleanup in _libs/lib.pyx
#33532
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
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,8 @@ | ||
from collections import abc | ||
from decimal import Decimal | ||
from fractions import Fraction | ||
from numbers import Number | ||
|
||
import sys | ||
import warnings | ||
|
||
import cython | ||
from cython import Py_ssize_t | ||
cimport cython | ||
from cython cimport Py_ssize_t | ||
|
||
from cpython.object cimport PyObject_RichCompareBool, Py_EQ | ||
from cpython.ref cimport Py_INCREF | ||
|
@@ -29,11 +24,6 @@ import numpy as np | |
cimport numpy as cnp | ||
from numpy cimport ( | ||
NPY_OBJECT, | ||
PyArray_Check, | ||
PyArray_GETITEM, | ||
PyArray_ITER_DATA, | ||
PyArray_ITER_NEXT, | ||
PyArray_IterNew, | ||
complex128_t, | ||
flatiter, | ||
float32_t, | ||
|
@@ -67,7 +57,7 @@ cdef extern from "src/parse_helper.h": | |
int floatify(object, float64_t *result, int *maybe_int) except -1 | ||
|
||
cimport pandas._libs.util as util | ||
from pandas._libs.util cimport is_nan, UINT64_MAX, INT64_MAX, INT64_MIN | ||
from pandas._libs.util cimport UINT64_MAX, INT64_MAX, INT64_MIN | ||
|
||
from pandas._libs.tslib import array_to_datetime | ||
from pandas._libs.tslibs.nattype cimport NPY_NAT, c_NaT as NaT | ||
|
@@ -287,6 +277,7 @@ def fast_unique_multiple(list arrays, sort: bool = True): | |
try: | ||
uniques.sort() | ||
except TypeError: | ||
import warnings | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Really unsure about this specific change, the reason I made this change is to avoid going through the python space for no reason, we are not getting into the |
||
warnings.warn( | ||
"The values in the array are unorderable. " | ||
"Pass `sort=False` to suppress this warning.", | ||
|
@@ -408,27 +399,27 @@ def fast_zip(list ndarrays): | |
|
||
# initialize tuples on first pass | ||
arr = ndarrays[0] | ||
it = <flatiter>PyArray_IterNew(arr) | ||
it = <flatiter>cnp.PyArray_IterNew(arr) | ||
for i in range(n): | ||
val = PyArray_GETITEM(arr, PyArray_ITER_DATA(it)) | ||
val = cnp.PyArray_GETITEM(arr, cnp.PyArray_ITER_DATA(it)) | ||
tup = PyTuple_New(k) | ||
|
||
PyTuple_SET_ITEM(tup, 0, val) | ||
Py_INCREF(val) | ||
result[i] = tup | ||
PyArray_ITER_NEXT(it) | ||
cnp.PyArray_ITER_NEXT(it) | ||
|
||
for j in range(1, k): | ||
arr = ndarrays[j] | ||
it = <flatiter>PyArray_IterNew(arr) | ||
it = <flatiter>cnp.PyArray_IterNew(arr) | ||
if len(arr) != n: | ||
raise ValueError("all arrays must be same length") | ||
|
||
for i in range(n): | ||
val = PyArray_GETITEM(arr, PyArray_ITER_DATA(it)) | ||
val = cnp.PyArray_GETITEM(arr, cnp.PyArray_ITER_DATA(it)) | ||
PyTuple_SET_ITEM(result[i], j, val) | ||
Py_INCREF(val) | ||
PyArray_ITER_NEXT(it) | ||
cnp.PyArray_ITER_NEXT(it) | ||
|
||
return result | ||
|
||
|
@@ -578,13 +569,16 @@ def array_equivalent_object(left: object[:], right: object[:]) -> bool: | |
# we are either not equal or both nan | ||
# I think None == None will be true here | ||
try: | ||
if PyArray_Check(x) and PyArray_Check(y): | ||
if cnp.PyArray_Check(x) and cnp.PyArray_Check(y): | ||
if not array_equivalent_object(x, y): | ||
return False | ||
elif (x is C_NA) ^ (y is C_NA): | ||
return False | ||
elif not (PyObject_RichCompareBool(x, y, Py_EQ) or | ||
(x is None or is_nan(x)) and (y is None or is_nan(y))): | ||
elif not ( | ||
PyObject_RichCompareBool(x, y, Py_EQ) | ||
or (x is None or util.is_nan(x)) | ||
and (y is None or util.is_nan(y)) | ||
): | ||
return False | ||
except TypeError as err: | ||
# Avoid raising TypeError on tzawareness mismatch | ||
|
@@ -1164,13 +1158,11 @@ cdef class Seen: | |
|
||
@property | ||
def is_bool(self): | ||
return not (self.datetime_ or self.numeric_ or self.timedelta_ | ||
or self.nat_) | ||
return not (self.datetime_ or self.numeric_ or self.timedelta_ or self.nat_) | ||
|
||
@property | ||
def is_float_or_complex(self): | ||
return not (self.bool_ or self.datetime_ or self.timedelta_ | ||
or self.nat_) | ||
return not (self.bool_ or self.datetime_ or self.timedelta_ or self.nat_) | ||
|
||
|
||
cdef object _try_infer_map(object v): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The import that are removed are: