Skip to content

Commit

Permalink
fix if/else
Browse files Browse the repository at this point in the history
  • Loading branch information
thoo committed Feb 16, 2019
1 parent 0a6e4be commit ad4a761
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
15 changes: 6 additions & 9 deletions pandas/core/reshape/pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,16 +368,13 @@ def _convert_by(by):
@Appender(_shared_docs['pivot'], indents=1)
def pivot(data, index=None, columns=None, values=None):
if values is None:
if index is None:
# Build cols for indexes.
cols = [columns]
cols = []
# Make acceptable for multiple column indexes.
if is_list_like(index):
cols.extend(index)
else:
# Accept multiple column indexes.
if is_list_like(index):
cols = index
else:
cols = [index]
cols.append(columns)
cols.append(index)
cols.append(columns)
append = index is None
indexed = data.set_index(cols, append=append)

Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/reshape/test_pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,11 @@ def test_pivot_multiple_columns_as_index(self, method):
result = df.pivot(index=['lev1', 'lev2'],
columns='lev3')
exp_columns = MultiIndex(levels=[['values'], [1, 2]],
codes=[[0, 0], [0, 1]],
names=[None, 'lev3'])
codes=[[0, 0], [0, 1]],
names=[None, 'lev3'])

expected = DataFrame(data=data, index=exp_index,
columns=exp_columns)
columns=exp_columns)
tm.assert_frame_equal(result, expected)

@pytest.mark.parametrize('method', [True, False])
Expand Down

0 comments on commit ad4a761

Please sign in to comment.