Skip to content

TST/REF: arithmetic tests for BooleanArray + consolidate with integer masked tests #34623

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 4 commits into from
Jun 14, 2020

Conversation

jorisvandenbossche
Copy link
Member

Follow-up on #34454

  • Move a bunch of tests from integer/test_arithmetic.py to masked/test_arithmetic.py so those can be shared with boolean (and once merged I can add float as well in the FloatingArray PR)
  • Added some more arithmetic tests to boolean/test_arithmetic.py to follow the same pattern as we have in integer/test_arithmetic.py.
  • The commong integer/boolean tests uncovered a bug in the BooleanArray implementation when dealing with a pd.NA scalar as other operand.

@jorisvandenbossche jorisvandenbossche added Bug Testing pandas testing functions or related to the test suite NA - MaskedArrays Related to pd.NA and nullable extension arrays labels Jun 6, 2020
@jorisvandenbossche jorisvandenbossche added this to the 1.1 milestone Jun 6, 2020
with pytest.raises(TypeError):
ops(pd.Timestamp("20180101"))
@pytest.fixture
def b():
Copy link
Member

Choose a reason for hiding this comment

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

would it be burdensome to give a and b more informative names?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you have a suggestion what you would find clearer?

Basically, before moving it to a fixture, I had:

def test_..():
    a = pd.array([True] * 3 + [False] * 3 + [None] * 3, dtype="boolean")
    b = pd.array([True, False, None] * 3, dtype="boolean")

    result = op(a, b)

in each test, and I would think in such a context you would be fine with those names?
And although I like defining those variables inside the test as more explicit, it was also a bit repetitive, so I moved it to a fixture.

Copy link
Contributor

Choose a reason for hiding this comment

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

i would call these left_array, right_array

Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed

@jbrockmendel
Copy link
Member

small comment; LGTM

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

looks pretty good

@@ -2758,3 +2759,28 @@ def get_cython_table_params(ndframe, func_names_and_expected):
if name == func_name
]
return results


def get_op_from_name(op_name):
Copy link
Contributor

Choose a reason for hiding this comment

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

can you type op_name and return type

with pytest.raises(TypeError):
ops(pd.Timestamp("20180101"))
@pytest.fixture
def b():
Copy link
Contributor

Choose a reason for hiding this comment

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

i would call these left_array, right_array

"floordiv",
"mod",
pytest.param(
"pow", marks=pytest.mark.xfail(reason="TODO follow int8 behaviour?")
Copy link
Contributor

Choose a reason for hiding this comment

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

is there an issue number?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not yet, will open one.

Copy link
Member Author

Choose a reason for hiding this comment

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

-> #34686

tm.assert_extension_array_equal(result, expected)


# Test generic charachteristics / errors
Copy link
Contributor

Choose a reason for hiding this comment

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

sp?

Copy link
Member Author

Choose a reason for hiding this comment

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

Does "sp" point to the typo in this title? Or did you mean something else?

tm.assert_series_equal(result, expected)


# Test generic charachteristics / errors
Copy link
Contributor

Choose a reason for hiding this comment

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

sp?

@jorisvandenbossche
Copy link
Member Author

Updated for all comments

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

lgtm.

@@ -2758,3 +2759,28 @@ def get_cython_table_params(ndframe, func_names_and_expected):
if name == func_name
]
return results


def get_op_from_name(op_name: str) -> Callable:
Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC we have something similiar in internals, maybe we should consolidate (just a thought) and certainly. in a followon

@jreback jreback merged commit 83016f3 into pandas-dev:master Jun 14, 2020
@jreback
Copy link
Contributor

jreback commented Jun 14, 2020

thanks @jorisvandenbossche

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug NA - MaskedArrays Related to pd.NA and nullable extension arrays Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants