-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Add tests in methods.py #23261
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
Add tests in methods.py #23261
Changes from 6 commits
75d9304
4a82fd7
dad9d27
1884b53
7ab9458
0a9fe11
c859b4d
9c55787
3760dce
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 |
---|---|---|
|
@@ -105,6 +105,37 @@ def test_factorize_equivalence(self, data_for_grouping, na_sentinel): | |
tm.assert_numpy_array_equal(l1, l2) | ||
self.assert_extension_array_equal(u1, u2) | ||
|
||
def test_fillna_copy_frame(self, data_missing): | ||
arr = data_missing.take([1, 1]) | ||
df = pd.DataFrame({"A": arr}) | ||
|
||
filled_val = df.iloc[0, 0] | ||
result = df.fillna(filled_val) | ||
assert df.values.base is not result.values.base | ||
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. I don't think this is correct. I believe that for DataFrames with EAs, Rather, I think the best we can do is |
||
|
||
if isinstance(arr, pd.SparseArray): | ||
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. rather than write like this, I would just override these tests for SparseArray 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. Done. |
||
assert df.A._values.to_dense() is arr.to_dense() | ||
else: | ||
assert df.A._values is arr | ||
|
||
def test_fillna_copy_series(self, data_missing): | ||
arr = data_missing.take([1, 1]) | ||
ser = pd.Series(arr) | ||
|
||
filled_val = ser[0] | ||
result = ser.fillna(filled_val) | ||
assert ser._values is not result._values | ||
|
||
if isinstance(arr, pd.SparseArray): | ||
assert ser._values.to_dense() is arr.to_dense() | ||
else: | ||
assert ser._values is arr | ||
|
||
def test_fillna_length_mismatch(self, data_missing): | ||
with (tm.assert_raises_regex(ValueError, | ||
"Length of 'value' does not match.")): | ||
data_missing.fillna(data_missing.take([1])) | ||
|
||
def test_combine_le(self, data_repeated): | ||
# GH 20825 | ||
# Test that combine works when doing a <= (le) comparison | ||
|
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.
I think that asserting
df.A._values is data_for_fillna
is needed here.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.
Would be good to test this for Series.fillna 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.
Thanks for the review. Sure I will. I just want to make sure I am on the right track.