-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG/API: make setitem-inplace preserve dtype when possible with PandasArray, IntegerArray, FloatingArray #39044
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 1 commit
6fffb02
160f3f7
de10708
ba98a99
84261a7
284f36a
2639b5c
b2aa366
7aeb2b5
715a602
b55155b
c72e566
0b9f343
cd6adbe
071ab1b
6ab44af
daacff8
450bf73
dba7c11
9258cbb
88309ab
1847209
6b8cc31
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 |
---|---|---|
|
@@ -33,8 +33,11 @@ | |
from pandas.tests.extension import base | ||
|
||
|
||
def make_data(): | ||
return list(range(1, 9)) + [pd.NA] + list(range(10, 98)) + [pd.NA] + [99, 100] | ||
def make_data(with_nas: bool = True): | ||
if with_nas: | ||
return list(range(1, 9)) + [pd.NA] + list(range(10, 98)) + [pd.NA] + [99, 100] | ||
|
||
return list(range(1, 101)) | ||
|
||
|
||
@pytest.fixture( | ||
|
@@ -53,9 +56,10 @@ def dtype(request): | |
return request.param() | ||
|
||
|
||
@pytest.fixture | ||
def data(dtype): | ||
return pd.array(make_data(), dtype=dtype) | ||
@pytest.fixture(params=[True, False]) | ||
def data(dtype, request): | ||
with_nas = request.param | ||
return pd.array(make_data(with_nas), dtype=dtype) | ||
|
||
|
||
@pytest.fixture | ||
|
@@ -198,7 +202,20 @@ class TestGetitem(base.BaseGetitemTests): | |
|
||
|
||
class TestSetitem(base.BaseSetitemTests): | ||
pass | ||
def test_setitem_series(self, data, full_indexer): | ||
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. Can you indicate here why it is overriding the base class? 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. comment added |
||
# https://github.com/pandas-dev/pandas/issues/32395 | ||
ser = expected = pd.Series(data, name="data") | ||
result = pd.Series(index=ser.index, dtype=object, name="data") | ||
|
||
key = full_indexer(ser) | ||
result.loc[key] = ser | ||
|
||
if not data._mask.any(): | ||
# GH#38896 like we do with ndarray, we set the values inplace | ||
# but cast to the new numpy dtype | ||
expected = pd.Series(data.to_numpy(data.dtype.numpy_dtype), name="data") | ||
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. Why are we converting to the numpy dtype here? That's also not the original dtype? |
||
|
||
self.assert_series_equal(result, expected) | ||
|
||
|
||
class TestMissing(base.BaseMissingTests): | ||
|
Uh oh!
There was an error while loading. Please reload this page.