Skip to content

Commit 37f2867

Browse files
committed
update tests and docs to be more generalizable with all string like dtypes
1 parent f69cfe6 commit 37f2867

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ Bug fixes
10321032
Categorical
10331033
^^^^^^^^^^^
10341034
- Bug in :class:`Categorical` where constructing from a pandas :class:`Series` or :class:`Index` with ``dtype='object'`` did not preserve the categories' dtype as ``object``; now the ``categories.dtype`` is preserved as ``object`` for these cases, while numpy arrays and Python sequences with ``dtype='object'`` continue to infer the most specific dtype (for example, ``str`` if all elements are strings) (:issue:`61778`)
1035-
- Bug in :class:`pandas.Categorical` displaying string categories without quotes when constructed from a Series with dtype "string" (:issue:`63045`)
1035+
- Bug in :class:`pandas.Categorical` displaying string categories without quotes when using "string" dtype (:issue:`63045`)
10361036
- Bug in :func:`Series.apply` where ``nan`` was ignored for :class:`CategoricalDtype` (:issue:`59938`)
10371037
- Bug in :func:`bdate_range` raising ``ValueError`` with frequency ``freq="cbh"`` (:issue:`62849`)
10381038
- Bug in :func:`testing.assert_index_equal` raising ``TypeError`` instead of ``AssertionError`` for incomparable ``CategoricalIndex`` when ``check_categorical=True`` and ``exact=False`` (:issue:`61935`)

pandas/tests/arrays/categorical/test_repr.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,10 +546,12 @@ def test_categorical_str_repr(self):
546546
expected = "[1, '2', 3, 4]\nCategories (4, object): [1, 3, 4, '2']"
547547
assert result == expected
548548

549-
def test_categorical_with_pandas_series(self):
549+
def test_categorical_with_pandas_series(self, string_dtype_no_object):
550550
# GH 63045
551-
s = Series(["apple", "banana", "cherry", "cherry"], dtype="string")
551+
s = Series(
552+
["apple", "banana", "cherry", "cherry"], dtype=string_dtype_no_object
553+
)
552554
result = repr(Categorical(s))
553-
expected = "['apple', 'banana', 'cherry', 'cherry']\nCategories (3, string): ['apple', 'banana', 'cherry']" # noqa: E501
555+
expected = f"['apple', 'banana', 'cherry', 'cherry']\nCategories (3, {string_dtype_no_object!s}): ['apple', 'banana', 'cherry']" # noqa: E501
554556

555557
assert result == expected

0 commit comments

Comments
 (0)