Skip to content

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

Merged
merged 9 commits into from
Oct 30, 2018
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions pandas/tests/extension/base/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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, df.values will all return a new ndarray, so this would be impossible to fail.

Rather, I think the best we can do is assert df.A.values is not result.A.values.


if isinstance(arr, pd.SparseArray):
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Expand Down
4 changes: 4 additions & 0 deletions pandas/tests/extension/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ def test_combine_add(self, data_repeated):
expected = pd.Series([a + val for a in list(orig_data1)])
self.assert_series_equal(result, expected)

@pytest.mark.skip(reason="Not Applicable")
def test_fillna_length_mismatch(self, data_missing):
pass


class TestCasting(base.BaseCastingTests):
pass
Expand Down
4 changes: 4 additions & 0 deletions pandas/tests/extension/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ class TestMethods(BaseInterval, base.BaseMethodsTests):
def test_combine_add(self, data_repeated):
pass

@pytest.mark.skip(reason="Not Applicable")
def test_fillna_length_mismatch(self, data_missing):
pass


class TestMissing(BaseInterval, base.BaseMissingTests):
# Index.fillna only accepts scalar `value`, so we have to skip all
Expand Down
4 changes: 4 additions & 0 deletions pandas/tests/extension/test_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ def test_combine_le(self, data_repeated):
], fill_value=False))
self.assert_series_equal(result, expected)

@pytest.mark.skip(reason="Not Applicable")
def test_fillna_length_mismatch(self, data_missing):
pass


class TestCasting(BaseSparseTests, base.BaseCastingTests):
pass
Expand Down