MCPcopy
hub / github.com/pandas-dev/pandas / _maybe_match_names

Method _maybe_match_names

pandas/core/indexes/multi.py:4302–4317  ·  view source on GitHub ↗

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 list of None if they have completely different names.

(self, other)

Source from the content-addressed store, hash-verified

4300 return self.copy(deep=False)
4301
4302 def _maybe_match_names(self, other):
4303 """
4304 Try to find common names to attach to the result of an operation between
4305 a and b. Return a consensus list of names if they match at least partly
4306 or list of None if they have completely different names.
4307 """
4308 if len(self.names) != len(other.names):
4309 return [None] * len(self.names)
4310 names = []
4311 for a_name, b_name in zip(self.names, other.names, strict=True):
4312 if a_name == b_name:
4313 names.append(a_name)
4314 else:
4315 # TODO: what if they both have np.nan for their names?
4316 names.append(None)
4317 return names
4318
4319 def _wrap_intersection_result(self, other, result) -> MultiIndex:
4320 _, result_names = self._convert_can_do_setop(other)

Callers 2

test_maybe_match_namesFunction · 0.80

Calls 1

appendMethod · 0.45

Tested by 1

test_maybe_match_namesFunction · 0.64