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 7 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
25 changes: 25 additions & 0 deletions pandas/tests/extension/base/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,31 @@ 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 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.

assert df.A._values is arr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed I think. That's asserting something different.

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! Thanks.


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
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
24 changes: 24 additions & 0 deletions pandas/tests/extension/test_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,30 @@ def test_combine_le(self, data_repeated):
], fill_value=False))
self.assert_series_equal(result, expected)

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
assert df.A._values.to_dense() is arr.to_dense()

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
assert ser._values.to_dense() is arr.to_dense()

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


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