pandas-dev / pandas

Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more
https://pandas.pydata.org
BSD 3-Clause "New" or "Revised" License
43.82k stars 17.99k forks source link

REF: make _cast_pointwise_result an EA method #59895

Open jbrockmendel opened 1 month ago

jbrockmendel commented 1 month ago

In the extension tests.extension.base.ops.BaseOpsUtil we have a _cast_pointwise_result method that is used to patch the result of Series.combine to do appropriate dtype inference so that we have e.g.

expected = series + other
middle = series.combine(other, operator.add)
result = self._cast_pointwise_result(middle)
tm.assert_series_equal(result, expected)

(There is also a test_combine_add method which does not currently use _cast_pointwise_result but could. Also test_combine_le looks like we implemented an entirely separate pattern for customizing dtype inference in that test. I'll look into seeing if these can re-use the _cast_pointwise_result pattern.)

This cast_pointwise_result should just be an EA method. ATM we override it in the arrow, masked, and string tests (I suspect that we should be overriding it in the sparse tests but it looks like we skip a bunch of them instead).

This will effectively replace _from_scalars, which was a mis-feature. It will also let us de-kludge places where we use maybe_cast_pointwise_result and generally be more robust.

jbrockmendel commented 1 month ago

It also looks a lot like test_combine_add+test_combine_le are made redundant by more general tests in BaseComparisonOpsTests and BaseArithmeticOpsTests