Refactor DataFrame.combine for datetimelike · Issue #23079 · pandas-dev/pandas (original) (raw)
In DataFrame.combine, we handle datetimelike data special.
needs_i8_conversion_i = needs_i8_conversion(new_dtype) |
---|
We attempt to pass a third argument to the combining func
. This breaks things like
In [16]: def combiner(x, y): return x
In [17]: a = pd.DataFrame({"A": range(4)})
In [18]: b = pd.DataFrame({"A": pd.date_range('2017', periods=4)})
In [19]: a.combine(a, combiner) Out[19]: A 0 0 1 1 2 2 3 3
In [20]: b.combine(b, combiner)
TypeError Traceback (most recent call last) in ----> 1 b.combine(b, combiner)
~/sandbox/pandas/pandas/core/frame.py in combine(self, other, func, fill_value, overwrite) 5116 needs_i8_conversion_i = needs_i8_conversion(new_dtype) 5117 if needs_i8_conversion_i: -> 5118 arr = func(series, otherSeries, True) 5119 else: 5120 arr = func(series, otherSeries)
TypeError: combiner() takes 2 positional arguments but 3 were given
We could document that, but it still feels hacky. I'd rather that the combiner
func infer whether an i8 conversion is needed.
xref #3595