Skip to content
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

Merged
merged 4 commits into from
Apr 10, 2020
Merged
Changes from 1 commit
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
74 changes: 37 additions & 37 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

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

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
Expand Down Expand Up @@ -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 = {
Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we actually get anything from typing this?

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:
Expand Down Expand Up @@ -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:
Expand Down