Skip to content

BUG/PERF: Use EA in Index.get_value #24204

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 3 commits into from
Dec 10, 2018
Merged
Changes from 1 commit
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
Prev Previous commit
Use monkeypatch
  • Loading branch information
TomAugspurger committed Dec 10, 2018
commit 49c596757e7f2caf563705e7296a14c751de9e5e
23 changes: 19 additions & 4 deletions pandas/tests/arrays/categorical/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,28 @@ def test_mask_with_boolean_raises(index):
s[idx]


class NonCoercaibleCategorical(Categorical):
def __array__(self, dtype=None):
@pytest.fixture
def non_coercible_categorical(monkeypatch):
"""
Monkeypatch Categorical.__array__ to ensure no implicit conversion.

Raises
------
ValueError
When Categorical.__array__ is called.
"""
# TODO(Categorical): identify other places where this may be
# useful and move to a conftest.py
def array(self, dtype=None):
raise ValueError("I cannot be converted.")

with monkeypatch.context() as m:
m.setattr(Categorical, "__array__", array)
yield

def test_series_at():
arr = NonCoercaibleCategorical(['a', 'b', 'c'])

def test_series_at(non_coercible_categorical):
arr = Categorical(['a', 'b', 'c'])
ser = Series(arr)
result = ser.at[0]
assert result == 'a'