fix(python): Raise for incompatible array casting in series construction #17900
+34
−0
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.
In #17743 constructing series objects from numpy arrays, when using a polars array dtype, may allow for unwanted coercion. For example, you may pass a polars int array to dtype and it may cast the numpy float array to int, which is obviously undesirable.
I debated throttling this behavior based on the
strict
argument, which is passed to theSeries
constructor. I decided not to allow an override to this edge case check since I (personally) would want this exception raised in all cases. If the core dev team thinks otherwise I can of course alter this.The logic I wrote was for this specific edge case but there may be others I just am not thinking about. This is why I broke the logic out to a separate checking function.