-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
CoW: __array__ not recognizing ea dtypes #51966
Changes from 13 commits
3a08a45
38453c4
ee751b4
a4eb612
c515870
5568ec2
e9641ad
bf1f9de
8922467
413fc7c
9681861
2d8a2f2
42368e0
5c0f1bb
4572e4a
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 |
---|---|---|
|
@@ -119,3 +119,57 @@ def test_ravel_read_only(using_copy_on_write, order): | |
if using_copy_on_write: | ||
assert arr.flags.writeable is False | ||
assert np.shares_memory(get_array(ser), arr) | ||
|
||
|
||
def test_series_array_ea_dtypes(using_copy_on_write): | ||
ser = Series([1, 2, 3], dtype="Int64") | ||
arr = np.asarray(ser, dtype="int64") | ||
assert np.shares_memory(arr, get_array(ser)) | ||
if using_copy_on_write: | ||
assert arr.flags.writeable is False | ||
else: | ||
assert arr.flags.writeable is True | ||
|
||
arr = np.asarray(ser) | ||
assert not np.shares_memory(arr, get_array(ser)) | ||
assert arr.flags.writeable is True | ||
|
||
|
||
def test_dataframe_array_ea_dtypes(using_copy_on_write): | ||
df = DataFrame({"a": [1, 2, 3]}, dtype="Int64") | ||
arr = np.asarray(df, dtype="int64") | ||
# TODO: This should be able to share memory, but we are roundtripping | ||
# through object | ||
assert not np.shares_memory(arr, get_array(df, "a")) | ||
assert arr.flags.writeable is True | ||
|
||
arr = np.asarray(df) | ||
if using_copy_on_write: | ||
# TODO(CoW): This should be True | ||
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. Not this one, because without specifying 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. Yes exactly, this triggers a copy and hence the array should be writeable? |
||
assert arr.flags.writeable is False | ||
else: | ||
assert arr.flags.writeable is True | ||
|
||
|
||
def test_dataframe_array_string_dtype(using_copy_on_write, using_array_manager): | ||
df = DataFrame({"a": ["a", "b"]}, dtype="string") | ||
arr = np.asarray(df) | ||
if not using_array_manager: | ||
assert np.shares_memory(arr, get_array(df, "a")) | ||
if using_copy_on_write: | ||
assert arr.flags.writeable is False | ||
else: | ||
assert arr.flags.writeable is True | ||
|
||
|
||
def test_dataframe_multiple_numpy_dtypes(): | ||
df = DataFrame({"a": [1, 2, 3], "b": 1.5}) | ||
arr = np.asarray(df) | ||
assert not np.shares_memory(arr, get_array(df, "a")) | ||
assert arr.flags.writeable is True | ||
|
||
|
||
def test_empty_dataframe(): | ||
df = DataFrame() | ||
arr = np.asarray(df) | ||
assert arr.flags.writeable is 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.
The
arr is values
might prevent catching some EA cases, since it seems that_values
can still return an EA (so the EA->ndarray conversion only happens inarr = np.asarray(values ..)
).Example (running with this PR):
For series you left out this check, so maybe can be done here as well?
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.
good point, thx