You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of Polars.
Issue description
I guess this is kind of a stupid issue, because why would you ever mix numpy arrays with polars Series? But I guess if it’s allowed, then it should be done right..
I give a few examples of strange behavior in the code below.
Example 1:
Pylance reports that result_1 will have type NDArray[bool_], but it is actually a Series.
Example 2:
Dtype depends on order of summands.
Example 3:
In this example, the array has length > 1.
Now array + Series works, but Series + array raises ValueError.
Reproducible example
importnumpyasnpimportpolarsaspl# Example 1sx=pl.Series(values=[1, 1])
y=np.array([1.0])
result_1=y+sxprint("Example 1:", type(result_1))
# Example 2sx=pl.Series(values=[1, 1])
y=np.array([1.0])
left=sx+yright=y+sxprint("Example 2:", left.dtype, right.dtype)
# Example 3sx=pl.Series(values=[1, 1])
y=np.array([1, 1])
result_3=y+sxprint("Example 3: sx + y works")
try:
result_3=sx+yexceptValueErrorase:
print("Example 3: sx + y gives this error.", e)
"""Example 1: <class 'polars.internals.series.series.Series'>Example 2: Int64 Float64Example 3: sx + y worksExample 3: sx + y gives this error. Cannot convert Python type <class 'numpy.ndarray'> to Int64"""
Expected behavior
I'm not 100% confident about the intended behavior, but this is what I think.
Example 1:
Ideally, the type checker would know the result is a Series.
Example 2:
The result should have dtype Float64 in either case.
Example 3:
If array + Series is allowed, then Series + array should be allowed.
The typing issue in example 1 we cannot do anything about, as it is the typing of the Numpy array, see for example numpy/numpy#22064 .
For examples 2 & 3, what I have done in #6983 is to cast the Numpy array to a pl.Series for the common arithmetic operations. As you said, these operations are not commonly done, so expect some rough edges. But do keep reporting those, happy to cover more if it is reasonable.
Polars version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of Polars.
Issue description
I guess this is kind of a stupid issue, because why would you ever mix numpy arrays with polars Series? But I guess if it’s allowed, then it should be done right..
I give a few examples of strange behavior in the code below.
Example 1:
Pylance reports that
result_1
will have typeNDArray[bool_]
, but it is actually a Series.Example 2:
Dtype depends on order of summands.
Example 3:
In this example, the array has length > 1.
Now
array + Series
works, butSeries + array
raises ValueError.Reproducible example
Expected behavior
I'm not 100% confident about the intended behavior, but this is what I think.
Example 1:
Ideally, the type checker would know the result is a Series.
Example 2:
The result should have dtype
Float64
in either case.Example 3:
If
array + Series
is allowed, thenSeries + array
should be allowed.Installed versions
The text was updated successfully, but these errors were encountered: