EA: add back _from_scalar / cast_pointwise_result backwards compat #63367
+107
−17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This follows-up on the comments here #62105 (comment) (on the PR that introduced
_cast_pointwise_result/ removed_from_scalars)This PR does a few things:
_cast_pointwise_resultstill does the minimal effort to try to return an instance of itself (the current implementation never returned the EA itself)._from_scalarsfor back compat with external EAs that already implemented this logic by overriding that method. This might only be geopandas, so also fine with eventually deprecating that method (and then_cast_pointwise_resultcan directly call_from_sequence, i.e. what the default impl for_from_scalarsdoes now)cast_pointwise_resultfunctional wrapper aroundEA._cast_pointwise_result. The reason for this is that I don't think the EA should be responsible to know all kinds of (optional) type inference of pandas, it should just take care of the type inference to its own types.result = super()._cast_pointwise_result(values), and we can document that they should do that (and then we can update the base class implementation whenever type inference defaults/options change). My feeling is that it is cleaner to not require that (i.e. let the EA handle just what it knows about, which is less error prone) and have that general logic outside of the EA, but I can also roll that back._cast_pointwise_resultfor EA authors to clarify what this method should do (but this might need to be updated depending on the above)cc @jbrockmendel