|
14 | 14 | from pandas.util._decorators import Appender
|
15 | 15 |
|
16 | 16 | from pandas.core.dtypes.common import is_array_like, is_list_like
|
17 |
| -from pandas.core.dtypes.generic import ABCDataFrame, ABCIndexClass, ABCSeries |
| 17 | +from pandas.core.dtypes.generic import ABCDataFrame, ABCSeries |
18 | 18 | from pandas.core.dtypes.missing import isna
|
19 | 19 |
|
20 | 20 | from pandas.core import algorithms
|
|
25 | 25 | get_array_op,
|
26 | 26 | logical_op,
|
27 | 27 | )
|
28 |
| -from pandas.core.ops.common import unpack_zerodim_and_defer # noqa:F401 |
| 28 | +from pandas.core.ops.common import ( # noqa:F401 |
| 29 | + get_op_result_name, |
| 30 | + unpack_zerodim_and_defer, |
| 31 | +) |
29 | 32 | from pandas.core.ops.docstrings import (
|
30 | 33 | _flex_comp_doc_FRAME,
|
31 | 34 | _op_descriptions,
|
|
76 | 79 |
|
77 | 80 | COMPARISON_BINOPS: Set[str] = {"eq", "ne", "lt", "gt", "le", "ge"}
|
78 | 81 |
|
79 |
| -# ----------------------------------------------------------------------------- |
80 |
| -# Ops Wrapping Utilities |
81 |
| - |
82 |
| - |
83 |
| -def get_op_result_name(left, right): |
84 |
| - """ |
85 |
| - Find the appropriate name to pin to an operation result. This result |
86 |
| - should always be either an Index or a Series. |
87 |
| -
|
88 |
| - Parameters |
89 |
| - ---------- |
90 |
| - left : {Series, Index} |
91 |
| - right : object |
92 |
| -
|
93 |
| - Returns |
94 |
| - ------- |
95 |
| - name : object |
96 |
| - Usually a string |
97 |
| - """ |
98 |
| - # `left` is always a Series when called from within ops |
99 |
| - if isinstance(right, (ABCSeries, ABCIndexClass)): |
100 |
| - name = _maybe_match_name(left, right) |
101 |
| - else: |
102 |
| - name = left.name |
103 |
| - return name |
104 |
| - |
105 |
| - |
106 |
| -def _maybe_match_name(a, b): |
107 |
| - """ |
108 |
| - Try to find a name to attach to the result of an operation between |
109 |
| - a and b. If only one of these has a `name` attribute, return that |
110 |
| - name. Otherwise return a consensus name if they match of None if |
111 |
| - they have different names. |
112 |
| -
|
113 |
| - Parameters |
114 |
| - ---------- |
115 |
| - a : object |
116 |
| - b : object |
117 |
| -
|
118 |
| - Returns |
119 |
| - ------- |
120 |
| - name : str or None |
121 |
| -
|
122 |
| - See Also |
123 |
| - -------- |
124 |
| - pandas.core.common.consensus_name_attr |
125 |
| - """ |
126 |
| - a_has = hasattr(a, "name") |
127 |
| - b_has = hasattr(b, "name") |
128 |
| - if a_has and b_has: |
129 |
| - if a.name == b.name: |
130 |
| - return a.name |
131 |
| - else: |
132 |
| - # TODO: what if they both have np.nan for their names? |
133 |
| - return None |
134 |
| - elif a_has: |
135 |
| - return a.name |
136 |
| - elif b_has: |
137 |
| - return b.name |
138 |
| - return None |
139 |
| - |
140 | 82 |
|
141 | 83 | # -----------------------------------------------------------------------------
|
142 | 84 | # Masking NA values and fallbacks for operations numpy does not support
|
|
0 commit comments