-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Performance of maybe_box_datetimelike #30520 #30531
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
Closed
Closed
Changes from 13 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
74f4b8b
Issue #30520
ivan-vasilev dcb45ed
Issue #30520
ivan-vasilev 6a2511c
Issue #30520 works for timedeltas as well
ivan-vasilev 54cb25e
Issue #30520 check for NaT values
ivan-vasilev 9d751b9
new lines using parentheses
ivan-vasilev 524150c
Issue #30520 more readable code + specifically check for NaT
ivan-vasilev c9699d9
code formatting
ivan-vasilev 65ab964
code formatting
ivan-vasilev 48cc580
first attempt at ASV performance test
ivan-vasilev 81d66b0
import sorting fix
ivan-vasilev 1747098
inference py blank lines at the end of the file removed
ivan-vasilev 894ee24
inference.py imports fix
ivan-vasilev bdc8eb4
imports sorted with isort
ivan-vasilev bb37c8b
Merge pull request #1 from pandas-dev/master
ivan-vasilev b4de215
formatting and import fixes
ivan-vasilev d233945
Merge branch 'master' of https://github.com/ivan-vasilev/pandas
ivan-vasilev 995326d
imports formatting fix
ivan-vasilev 961ebb7
import reordering
ivan-vasilev 4071dde
new line at the end of the file
ivan-vasilev 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
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 |
---|---|---|
|
@@ -72,7 +72,6 @@ def consensus_name_attr(objs): | |
|
||
|
||
def maybe_box(indexer, values, obj, key): | ||
|
||
# if we have multiples coming back, box em | ||
if isinstance(values, np.ndarray): | ||
return obj[indexer.get_loc(key)] | ||
|
@@ -84,6 +83,11 @@ def maybe_box(indexer, values, obj, key): | |
def maybe_box_datetimelike(value): | ||
# turn a datetime like into a Timestamp/timedelta as needed | ||
|
||
if isinstance(value, (tslibs.Timedelta, tslibs.Timestamp)) or ( | ||
value is tslibs.NaT | ||
): | ||
return value | ||
|
||
if isinstance(value, (np.datetime64, datetime)): | ||
value = tslibs.Timestamp(value) | ||
elif isinstance(value, (np.timedelta64, timedelta)): | ||
|
@@ -119,7 +123,7 @@ def is_bool_indexer(key: Any) -> bool: | |
""" | ||
na_msg = "cannot index with vector containing NA / NaN values" | ||
if isinstance(key, (ABCSeries, np.ndarray, ABCIndex)) or ( | ||
is_array_like(key) and is_extension_array_dtype(key.dtype) | ||
is_array_like(key) and is_extension_array_dtype(key.dtype) | ||
): | ||
if key.dtype == np.object_: | ||
key = np.asarray(values_from_object(key)) | ||
|
@@ -215,7 +219,6 @@ def try_sort(iterable): | |
|
||
|
||
def asarray_tuplesafe(values, dtype=None): | ||
|
||
if not (isinstance(values, (list, tuple)) or hasattr(values, "__array__")): | ||
values = list(values) | ||
elif isinstance(values, ABCIndexClass): | ||
|
@@ -284,10 +287,10 @@ def is_null_slice(obj): | |
We have a null slice. | ||
""" | ||
return ( | ||
isinstance(obj, slice) | ||
and obj.start is None | ||
and obj.stop is None | ||
and obj.step is None | ||
isinstance(obj, slice) | ||
and obj.start is None | ||
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. can you avoid other whitespace changes |
||
and obj.stop is None | ||
and obj.step is None | ||
) | ||
|
||
|
||
|
@@ -304,7 +307,7 @@ def is_full_slice(obj, l): | |
We have a full length slice. | ||
""" | ||
return ( | ||
isinstance(obj, slice) and obj.start == 0 and obj.stop == l and obj.step is None | ||
isinstance(obj, slice) and obj.start == 0 and obj.stop == l and obj.step is None | ||
) | ||
|
||
|
||
|
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.
you need to leave this