Skip to content

Commit e9d00de

Browse files
Justin SolinskyJustin Solinsky
Justin Solinsky
authored and
Justin Solinsky
committed
GH15219 Documentation fixes based on feedback
1 parent d278d62 commit e9d00de

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

doc/source/whatsnew/v0.20.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ Other enhancements
157157
- HTML table output skips ``colspan`` or ``rowspan`` attribute if equal to 1. (:issue:`15403`)
158158

159159
.. _ISO 8601 duration: https://en.wikipedia.org/wiki/ISO_8601#Durations
160-
- ``ignore_ordered`` argument added to ``pd.types.concat.union_categoricals``; setting the argument to true will ignore the ordered attribute of unioned categoricals (:issue:`13410`)
160+
- ``ignore_ordered`` argument added to ``pd.types.concat.union_categoricals``; setting the argument to true will ignore the ordered attribute of unioned categoricals (:issue:`13410`) . See the :ref:`categorical union docs <categorical.union>` for more information.
161161

162162
.. _whatsnew_0200.api_breaking:
163163

pandas/tests/tools/test_concat.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -1663,17 +1663,27 @@ def test_union_categoricals_ordered(self):
16631663
union_categoricals([c1, c2])
16641664

16651665
def test_union_categoricals_ignore_order(self):
1666+
# GH 15219
16661667
c1 = Categorical([1, 2, 3], ordered=True)
16671668
c2 = Categorical([1, 2, 3], ordered=False)
16681669

16691670
res = union_categoricals([c1, c2], ignore_order=True)
16701671
exp = Categorical([1, 2, 3, 1, 2, 3])
16711672
tm.assert_categorical_equal(res, exp)
16721673

1674+
msg = 'Categorical.ordered must be the same'
1675+
with tm.assertRaisesRegexp(TypeError, msg):
1676+
union_categoricals([c1, c2], ignore_order=False)
1677+
16731678
res = union_categoricals([c1, c1], ignore_order=True)
16741679
exp = Categorical([1, 2, 3, 1, 2, 3])
16751680
tm.assert_categorical_equal(res, exp)
16761681

1682+
res = union_categoricals([c1, c1], ignore_order=False)
1683+
exp = Categorical([1, 2, 3, 1, 2, 3],
1684+
categories=[1, 2, 3], ordered=True)
1685+
tm.assert_categorical_equal(res, exp)
1686+
16771687
c1 = Categorical([1, 2, 3, np.nan], ordered=True)
16781688
c2 = Categorical([3, 2], categories=[1, 2, 3], ordered=True)
16791689

@@ -1688,7 +1698,8 @@ def test_union_categoricals_ignore_order(self):
16881698
exp = Categorical([1, 2, 3, 1, 2, 3])
16891699
tm.assert_categorical_equal(res, exp)
16901700

1691-
res = union_categoricals([c2, c1], ignore_order=True, sort_categories=True)
1701+
res = union_categoricals([c2, c1], ignore_order=True,
1702+
sort_categories=True)
16921703
exp = Categorical([1, 2, 3, 1, 2, 3], categories=[1, 2, 3])
16931704
tm.assert_categorical_equal(res, exp)
16941705

@@ -1698,6 +1709,13 @@ def test_union_categoricals_ignore_order(self):
16981709
expected = Categorical([1, 2, 3, 4, 5, 6])
16991710
tm.assert_categorical_equal(result, expected)
17001711

1712+
msg = "to union ordered Categoricals, all categories must be the same"
1713+
with tm.assertRaisesRegexp(TypeError, msg):
1714+
union_categoricals([c1, c2], ignore_order=False)
1715+
1716+
with tm.assertRaisesRegexp(TypeError, msg):
1717+
union_categoricals([c1, c2])
1718+
17011719
def test_union_categoricals_sort(self):
17021720
# GH 13846
17031721
c1 = Categorical(['x', 'y', 'z'])

pandas/types/concat.py

+2
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ def union_categoricals(to_union, sort_categories=False, ignore_order=False):
226226
If true, the ordered attribute of the Categoricals will be ignored.
227227
Results in an unordered categorical.
228228
229+
.. versionadded:: 0.20.0
230+
229231
Returns
230232
-------
231233
result : Categorical

0 commit comments

Comments
 (0)