-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
CLN: Static types in pandas/_lib/lib.pyx
#33329
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,12 +103,10 @@ def memory_usage_of_objects(arr: object[:]) -> int64_t: | |
|
||
Does not include the actual bytes of the pointers | ||
""" | ||
i: Py_ssize_t | ||
n: Py_ssize_t | ||
size: int64_t | ||
cdef: | ||
Py_ssize_t i, n = len(arr) | ||
int64_t size = 0 | ||
|
||
size = 0 | ||
n = len(arr) | ||
for i in range(n): | ||
size += arr[i].__sizeof__() | ||
return size | ||
|
@@ -1000,36 +998,37 @@ cdef inline bint c_is_list_like(object obj, bint allow_sets): | |
) | ||
|
||
|
||
_TYPE_MAP = { | ||
'categorical': 'categorical', | ||
'category': 'categorical', | ||
'int8': 'integer', | ||
'int16': 'integer', | ||
'int32': 'integer', | ||
'int64': 'integer', | ||
'i': 'integer', | ||
'uint8': 'integer', | ||
'uint16': 'integer', | ||
'uint32': 'integer', | ||
'uint64': 'integer', | ||
'u': 'integer', | ||
'float32': 'floating', | ||
'float64': 'floating', | ||
'f': 'floating', | ||
'complex64': 'complex', | ||
'complex128': 'complex', | ||
'c': 'complex', | ||
'string': 'string', | ||
'S': 'bytes', | ||
'U': 'string', | ||
'bool': 'boolean', | ||
'b': 'boolean', | ||
'datetime64[ns]': 'datetime64', | ||
'M': 'datetime64', | ||
'timedelta64[ns]': 'timedelta64', | ||
'm': 'timedelta64', | ||
'interval': 'interval', | ||
} | ||
cdef: | ||
dict _TYPE_MAP = { | ||
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. do we actually get anything from typing this? one of the pie-in-the-sky goals is to get the cython code close enough to valid python that we can make flake8 work on it; this is going in the other direction 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.
I looked at the generated C code, and it looks like we don't gain anything from typing this, I assumed we did, but I guess not. |
||
'categorical': 'categorical', | ||
'category': 'categorical', | ||
'int8': 'integer', | ||
'int16': 'integer', | ||
'int32': 'integer', | ||
'int64': 'integer', | ||
'i': 'integer', | ||
'uint8': 'integer', | ||
'uint16': 'integer', | ||
'uint32': 'integer', | ||
'uint64': 'integer', | ||
'u': 'integer', | ||
'float32': 'floating', | ||
'float64': 'floating', | ||
'f': 'floating', | ||
'complex64': 'complex', | ||
'complex128': 'complex', | ||
'c': 'complex', | ||
'string': 'string', | ||
'S': 'bytes', | ||
'U': 'string', | ||
'bool': 'boolean', | ||
'b': 'boolean', | ||
'datetime64[ns]': 'datetime64', | ||
'M': 'datetime64', | ||
'timedelta64[ns]': 'timedelta64', | ||
'm': 'timedelta64', | ||
'interval': 'interval', | ||
} | ||
|
||
# types only exist on certain platform | ||
try: | ||
|
@@ -1173,12 +1172,13 @@ cdef class Seen: | |
or self.nat_) | ||
|
||
|
||
cdef _try_infer_map(v): | ||
cdef object _try_infer_map(object v): | ||
""" | ||
If its in our map, just return the dtype. | ||
""" | ||
cdef: | ||
object attr, val | ||
object val | ||
str attr | ||
for attr in ['name', 'kind', 'base']: | ||
val = getattr(v.dtype, attr) | ||
if val in _TYPE_MAP: | ||
|
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.
we put this in because it is consistent with pure-python syntax