Skip to content
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

StringArray comparisions return BooleanArray #30231

Merged
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
Next Next commit
fixups
TomAugspurger committed Dec 12, 2019

Verified

This commit was signed with the committer’s verified signature.
commit 240c6ee8045f361de98f9a534e34ed2e4559e2f0
11 changes: 6 additions & 5 deletions doc/source/user_guide/text.rst
Original file line number Diff line number Diff line change
@@ -94,11 +94,12 @@ l. For ``StringDtype``, :ref:`string accessor methods<api.series.str>`
2. Some string methods, like :meth:`Series.str.decode` are not available
on ``StringArray`` because ``StringArray`` only holds strings, not
bytes.
3. In comparision operations, :class:`StringArray` and ``Series`` backed
by a ``StringArray`` will return an object with :class:`BooleanDtype`,
rather than a ``bool`` or ``object`` dtype object, depending on whether
there are missing values.

3. In comparision operations, :class:`arrays.StringArray` and ``Series`` backed
by a ``StringArray`` will return an object with :class:`arrays.BooleanDtype`,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
by a ``StringArray`` will return an object with :class:`arrays.BooleanDtype`,
by a ``StringArray`` will return an object with :class:`BooleanDtype`,

rather than a ``bool`` dtype object, depending on whether
there are missing values. Missing values in a ``StringArray`` will propagate
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 a reason we are not always returning a BooleanArray, or am I mis-reading this? this would be very confusing if this is indeed the case.

Copy link
Member

Choose a reason for hiding this comment

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

I think it is stated confusingly. When the dtype is "string" (not object), comparisons always return BooleanDtype.
Tom, I think you can removed the ", depending on whether there are missing values"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

in comparision operations, rather than always comparing unequal like
:attr:`numpy.nan`.

Everything else that follows in the rest of this document applies equally to
``string`` and ``object`` dtype.
2 changes: 0 additions & 2 deletions pandas/tests/arrays/string_/test_string.py
Original file line number Diff line number Diff line change
@@ -161,7 +161,6 @@ def test_comparison_methods_scalar(all_compare_operators):
other = "a"
result = getattr(a, op_name)(other)
expected = np.array([getattr(item, op_name)(other) for item in a], dtype=object)
expected[1] = None
expected = pd.array(expected, dtype="boolean")
tm.assert_extension_array_equal(result, expected)

@@ -177,7 +176,6 @@ def test_comparison_methods_array(all_compare_operators):
other = [None, None, "c"]
result = getattr(a, op_name)(other)
expected = np.empty_like(a, dtype="object")
expected[:2] = None
expected[-1] = getattr(other[-1], op_name)(a[-1])
expected = pd.array(expected, dtype="boolean")
tm.assert_extension_array_equal(result, expected)