Skip to content

Commit 54640ff

Browse files
committed
Comment updates
1 parent b1c47aa commit 54640ff

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

Diff for: doc/source/whatsnew/v0.21.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ length 2+ levels, so a :class:`MultiIndex` is always returned from all of the
294294

295295
pd.MultiIndex.from_tuples([('a',), ('b',)])
296296

297+
This affects all the ``MultiIndex`` constructors. (:issue:`17178`)
298+
297299
.. _whatsnew_0210.api:
298300

299301
Other API Changes

Diff for: pandas/core/indexes/base.py

+8
Original file line numberDiff line numberDiff line change
@@ -4032,6 +4032,10 @@ def _ensure_index_from_sequences(sequences, names=None):
40324032
MultiIndex(levels=[['a'], ['a', 'b']],
40334033
labels=[[0, 0], [0, 1]],
40344034
names=['L1', 'L2'])
4035+
4036+
See Also
4037+
--------
4038+
_ensure_index
40354039
"""
40364040
from .multi import MultiIndex
40374041

@@ -4068,6 +4072,10 @@ def _ensure_index(index_like, copy=False):
40684072
>>> _ensure_index([['a', 'a'], ['b', 'c']])
40694073
MultiIndex(levels=[['a'], ['b', 'c']],
40704074
labels=[[0, 0], [0, 1]])
4075+
4076+
See Also
4077+
--------
4078+
_ensure_index_from_sequences
40714079
"""
40724080
if isinstance(index_like, Index):
40734081
if copy:

Diff for: pandas/core/reshape/reshape.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -450,12 +450,12 @@ def _slow_pivot(index, columns, values):
450450

451451
def unstack(obj, level, fill_value=None):
452452
if isinstance(level, (tuple, list)):
453-
if len(level) == 1:
454-
# unstack_multiple only handles MultiIndexes,
453+
if len(level) != 1:
454+
# _unstack_multiple only handles MultiIndexes,
455455
# and isn't needed for a single level
456-
level = level[0]
457-
else:
458456
return _unstack_multiple(obj, level)
457+
else:
458+
level = level[0]
459459

460460
if isinstance(obj, DataFrame):
461461
if isinstance(obj.index, MultiIndex):

Diff for: pandas/tests/io/parser/dtypes.py

+14
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
import pytest
9+
from textwrap import dedent
910

1011
import numpy as np
1112
import pandas as pd
@@ -149,6 +150,19 @@ def test_categorical_dtype_chunksize(self):
149150
for actual, expected in zip(actuals, expecteds):
150151
tm.assert_frame_equal(actual, expected)
151152

153+
def test_categorical_categoricaldtype(self):
154+
data = dedent("""\
155+
A,B
156+
1,a
157+
2,b""")
158+
dtype = CategoricalDtype(categories=['a', 'b', 'c'])
159+
expected = pd.DataFrame({
160+
"A": [1, 2],
161+
"B": pd.Categorical(['a', 'b'], categories=['a', 'b', 'c'])
162+
})[['A', 'B']]
163+
result = self.read_csv(StringIO(data), dtype={"B": dtype})
164+
tm.assert_frame_equal(result, expected)
165+
152166
def test_empty_pass_dtype(self):
153167
data = 'one,two'
154168
result = self.read_csv(StringIO(data), dtype={'one': 'u1'})

0 commit comments

Comments
 (0)