Skip to content

CLN: address TODOs #33886

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 3 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
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
16 changes: 5 additions & 11 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def is_iterator(obj: object) -> bool:
return PyIter_Check(obj)


def item_from_zerodim(val: object) -> object:
cpdef object item_from_zerodim(object val):
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add inline here?

Copy link
Member Author

Choose a reason for hiding this comment

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

could i guess, i dont think it makes a difference

Copy link
Member Author

Choose a reason for hiding this comment

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

on balance i prefer not to mix "inline" with "cpdef"

Copy link
Contributor

Choose a reason for hiding this comment

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

right that’s the question does this make a perf difference? as u have it vs master

Copy link
Member Author

@jbrockmendel jbrockmendel May 1, 2020

Choose a reason for hiding this comment

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

huh, if anything map_infer is somewhat slower in this PR than in master, and its worse with inline. so im going to revert this edit, remove the TODO comments, and in a separate branch look into if we can improve item_from_zerodim

Copy link
Member

Choose a reason for hiding this comment

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

I can open an issue about this separately, but our current inline strategy may be doing more harm than good. GCC has a -Winline flag that will tell you when a function declared with inline isn't actually inlined, and running this on Linux appears to produce 11 MB worth of warnings with a clean build of pandas

Copy link
Member Author

Choose a reason for hiding this comment

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

Yikes. Addressing the larger issue separately makes sense. For the purposes of this PR, is there something that should be changed?

Copy link
Member

Choose a reason for hiding this comment

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

Things lgtm here as is, but let's see what Jeff thinks

Copy link
Member

Choose a reason for hiding this comment

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

raised issue in #33926

Copy link
Contributor

Choose a reason for hiding this comment

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

no this is fine, but yeah looking at this generally is prob a good idea.

"""
If the value is a zerodim array, return the item it contains.

Expand Down Expand Up @@ -2344,11 +2344,8 @@ def map_infer_mask(ndarray arr, object f, const uint8_t[:] mask, bint convert=Tr
else:
val = f(arr[i])

if cnp.PyArray_IsZeroDim(val):
# unbox 0-dim arrays, GH#690
# TODO: is there a faster way to unbox?
# item_from_zerodim?
val = val.item()
# unbox 0-dim arrays, GH#690
val = item_from_zerodim(val)

result[i] = val

Expand Down Expand Up @@ -2386,11 +2383,8 @@ def map_infer(ndarray arr, object f, bint convert=True):
for i in range(n):
val = f(arr[i])

if cnp.PyArray_IsZeroDim(val):
# unbox 0-dim arrays, GH#690
# TODO: is there a faster way to unbox?
# item_from_zerodim?
val = val.item()
# unbox 0-dim arrays, GH#690
val = item_from_zerodim(val)

result[i] = val

Expand Down
8 changes: 0 additions & 8 deletions pandas/_libs/tslibs/timedeltas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1516,10 +1516,6 @@ class Timedelta(_Timedelta):

def __rmod__(self, other):
# Naive implementation, room for optimization
if hasattr(other, 'dtype') and other.dtype.kind == 'i':
# TODO: Remove this check with backwards-compat shim
# for integer / Timedelta is removed.
raise TypeError(f'Invalid dtype {other.dtype} for __mod__')
return self.__rdivmod__(other)[1]

def __divmod__(self, other):
Expand All @@ -1529,10 +1525,6 @@ class Timedelta(_Timedelta):

def __rdivmod__(self, other):
# Naive implementation, room for optimization
if hasattr(other, 'dtype') and other.dtype.kind == 'i':
# TODO: Remove this check with backwards-compat shim
# for integer / Timedelta is removed.
raise TypeError(f'Invalid dtype {other.dtype} for __mod__')
div = other // self
return div, other - div * self

Expand Down
6 changes: 1 addition & 5 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -1503,13 +1503,9 @@ def __rsub__(self, other):
# TODO: Can we simplify/generalize these cases at all?
raise TypeError(f"cannot subtract {type(self).__name__} from {other.dtype}")
elif is_timedelta64_dtype(self.dtype):
if lib.is_integer(other) or is_integer_dtype(other):
# need to subtract before negating, since that flips freq
# -self flips self.freq, messing up results
return -(self - other)

return (-self) + other

# We get here with e.g. datetime objects
return -(self - other)

def __iadd__(self, other):
Expand Down
1 change: 0 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -8989,7 +8989,6 @@ def _AXIS_NAMES(self) -> Dict[int, str]:


def _from_nested_dict(data):
# TODO: this should be seriously cythonized
new_data = collections.defaultdict(dict)
for index, s in data.items():
for col, v in s.items():
Expand Down
1 change: 0 additions & 1 deletion pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ def index_arithmetic_method(self, other):
return Index(result)

name = f"__{op.__name__}__"
# TODO: docstring?
return set_function_name(index_arithmetic_method, name, cls)


Expand Down
12 changes: 8 additions & 4 deletions pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,10 +668,14 @@ def intersection(self, other, sort=False):
if self.equals(other):
return self._get_reconciled_name_object(other)

if not is_dtype_equal(self.dtype, other.dtype):
# TODO: fastpath for if we have a different PeriodDtype
this = self.astype("O")
other = other.astype("O")
elif is_object_dtype(other.dtype):
return self.astype("O").intersection(other, sort=sort)

elif not is_dtype_equal(self.dtype, other.dtype):
# We can infer that the intersection is empty.
# assert_can_do_setop ensures that this is not just a mismatched freq
this = self[:0].astype("O")
other = other[:0].astype("O")
return this.intersection(other, sort=sort)

return self._setop(other, sort, opname="intersection")
Expand Down
1 change: 0 additions & 1 deletion pandas/core/internals/concat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# TODO: Needs a better name; too many modules are already called "concat"
from collections import defaultdict
import copy
from typing import List
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/sas/sasreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pandas.io.common import stringify_path


# TODO: replace with Protocol in Python 3.8
# TODO(PY38): replace with Protocol in Python 3.8
class ReaderBase(metaclass=ABCMeta):
"""
Protocol for XportReader and SAS7BDATReader classes.
Expand Down