-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Inserting array of same size with Series.loc raises ValueError #38266
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 6 commits
e2e9ad8
482f349
92d1960
f376ec5
0165b30
1aa4bed
ed16223
f054a0e
039a6f9
418254b
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 |
---|---|---|
|
@@ -1755,6 +1755,18 @@ def assert_equal(left, right, **kwargs): | |
raise NotImplementedError(type(left)) | ||
|
||
|
||
def assert_python_equal(left, right): | ||
""" | ||
Check left and right are equal w.r.t the ``==`` operator. | ||
|
||
Parameters | ||
---------- | ||
left : object | ||
right : object | ||
""" | ||
assert left == right | ||
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. ok, I'm guessing this is too much, but I failed to find helper funcs to assert list/tuple equality. 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. yeah don't do this, just do 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. ok |
||
|
||
|
||
def box_expected(expected, box_cls, transpose=True): | ||
""" | ||
Helper function to wrap the expected output of a test in a given box_class. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2072,3 +2072,32 @@ def test_loc_setitem_dt64tz_values(self): | |
s2["a"] = expected | ||
result = s2["a"] | ||
assert result == expected | ||
|
||
@pytest.mark.parametrize( | ||
"array_fn,assert_fn", | ||
[ | ||
(np.zeros, tm.assert_numpy_array_equal), | ||
(pd.array, tm.assert_extension_array_equal), | ||
(list, tm.assert_python_equal), | ||
(tuple, tm.assert_python_equal), | ||
], | ||
) | ||
@pytest.mark.parametrize("size", [0, 4, 5, 6]) | ||
def test_loc_iloc_setitem_with_listlike(self, size, array_fn, assert_fn): | ||
# GH37748 | ||
# testing insertion, in Series of size N (here 5), of listlike | ||
# of size 0, N-1, N, N+1 | ||
|
||
expected = array_fn([0] * size) | ||
|
||
ser = Series(0, index=list("abcde"), dtype="object") | ||
|
||
ser.loc["a"] = expected | ||
result = ser[0] | ||
assert_fn(result, expected) | ||
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. Is there a reason for not checking the whole Series? This would also avoid your helper function 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. good point, thanks |
||
|
||
ser = Series(0, index=list("abcde"), dtype="object") | ||
|
||
ser.iloc[0] = expected | ||
result = ser[0] | ||
assert_fn(result, expected) |
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.
you list 3 issues in the top of PR, what's missing?
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.
Ah, I added a whastnew note for #38271 and one for #37748.
In the PR, I listed #37486 because it is a particular case of #37748 (iloc on a Series with a list, both of size 1).
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.
Pls add the issue number to the note for #37748 then
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.
ok