-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG/API: prohibit dtype-changing IntervalArray.__setitem__ #32782
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
47202dd
9f21c62
477c441
bdaf49b
8735b58
755679c
23b6b93
3e5826c
934dabe
959f674
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -543,7 +543,11 @@ def __setitem__(self, key, value): | |
msg = f"'value' should be an interval type, got {type(value)} instead." | ||
raise TypeError(msg) from err | ||
|
||
if needs_float_conversion: | ||
raise ValueError("Cannot set float values for integer-backed IntervalArray") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The FWIW the behavior when setting float values without In [1]: import pandas as pd; import numpy as np
In [2]: ia = pd.arrays.IntervalArray.from_breaks(range(5))
In [3]: ia[0] = pd.Interval(0.9, 1.1)
In [4]: ia
Out[4]:
<IntervalArray>
[(0, 1], (1, 2], (2, 3], (3, 4]]
Length: 4, closed: right, dtype: interval[int64]
In [5]: a = np.arange(4)
In [6]: a[0] = 0.9
In [7]: a[1] = 1.1
In [8]: a
Out[8]: array([0, 1, 2, 3]) I'm not crazy about that behavior but I'm fine with it since it's consistent with numpy. |
||
|
||
key = check_array_indexer(self, key) | ||
|
||
# Need to ensure that left and right are updated atomically, so we're | ||
# forced to copy, update the copy, and swap in the new values. | ||
left = self.left.copy(deep=True) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're raising here we can remove the future references that are no longer being used:
pandas/pandas/core/arrays/interval.py
Lines 554 to 555 in 23b6b93
pandas/pandas/core/arrays/interval.py
Lines 560 to 561 in 23b6b93