Skip to content

ENH: return an OrderedDict from read_excel with sheetname=None #14571

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

Merged
merged 2 commits into from
Nov 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.20.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ New features
Other enhancements
^^^^^^^^^^^^^^^^^^


- ``pd.read_excel`` now preserves sheet order when using ``sheetname=None`` (:issue:`9930`)


.. _whatsnew_0200.api_breaking:
Expand Down
6 changes: 3 additions & 3 deletions pandas/io/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from pandas.tseries.period import Period
from pandas import json
from pandas.compat import (map, zip, reduce, range, lrange, u, add_metaclass,
string_types)
string_types, OrderedDict)
from pandas.core import config
from pandas.formats.printing import pprint_thing
import pandas.compat as compat
Expand Down Expand Up @@ -418,9 +418,9 @@ def _parse_cell(cell_contents, cell_typ):
sheets = [sheetname]

# handle same-type duplicates.
sheets = list(set(sheets))
sheets = list(OrderedDict.fromkeys(sheets).keys())

output = {}
output = OrderedDict()

for asheetname in sheets:
if verbose:
Expand Down
Binary file modified pandas/io/tests/data/test_multisheet.xls
Binary file not shown.
Binary file modified pandas/io/tests/data/test_multisheet.xlsm
Binary file not shown.
Binary file modified pandas/io/tests/data/test_multisheet.xlsx
Binary file not shown.
6 changes: 5 additions & 1 deletion pandas/io/tests/test_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,12 @@ def test_reading_all_sheets(self):
# See PR #9450
basename = 'test_multisheet'
dfs = self.get_exceldf(basename, sheetname=None)
expected_keys = ['Alpha', 'Beta', 'Charlie']
# ensure this is not alphabetical to test order preservation
expected_keys = ['Charlie', 'Alpha', 'Beta']
tm.assert_contains_all(expected_keys, dfs.keys())
# Issue 9930
# Ensure sheet order is preserved
tm.assert_equal(expected_keys, list(dfs.keys()))

def test_reading_multiple_specific_sheets(self):
# Test reading specific sheetnames by specifying a mixed list
Expand Down