-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
CLN: Implement multiindex handling for get_op_result_name #38323
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
Changes from 7 commits
7dc16c0
9118012
9051d13
64af404
18bd99a
6481675
4647cda
726474d
783262b
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 |
---|---|---|
|
@@ -93,7 +93,7 @@ def _maybe_match_name(a, b): | |
""" | ||
Try to find a name to attach to the result of an operation between | ||
a and b. If only one of these has a `name` attribute, return that | ||
name. Otherwise return a consensus name if they match of None if | ||
name. Otherwise return a consensus name if they match or None if | ||
they have different names. | ||
|
||
Parameters | ||
|
@@ -122,3 +122,30 @@ def _maybe_match_name(a, b): | |
elif b_has: | ||
return b.name | ||
return None | ||
|
||
|
||
def maybe_match_names_multiindex(a, b): | ||
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 type a, b and the return 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. Don't need to type this after moving? |
||
""" | ||
Try to find common names to attach to the result of an operation between | ||
a and b. Return a consensus list of names if they match at least partly | ||
or None if they have completely different names. | ||
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. this could just be in padnas/core/indexes/multi.py i think would be fine 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. Done |
||
|
||
Parameters | ||
---------- | ||
a : MultiIndex | ||
b : MultiIndex | ||
|
||
Returns | ||
------- | ||
name : list of optional str or None | ||
""" | ||
if len(a.names) != len(b.names): | ||
return None | ||
names = [] | ||
for a_name, b_name in zip(a.names, b.names): | ||
if a_name == b_name: | ||
names.append(a_name) | ||
else: | ||
# TODO: what if they both have np.nan for their names? | ||
names.append(None) | ||
return names |
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.
would rename this to maybe_match_names
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.
Done