Skip to content

Book created from a dict discards ordering #219

@craiga

Description

@craiga

Since Python 3.7, dictionaries preserve order, so I'd expect the following code to pass:

book = pyexcel.Book(
    {
        "Stuff": [["some", "data", "I", "can't", "parse"]],
        "Records": [["record_id"], ["a"], ["b"], ["c"]],
        "Quarters": [
            ["id", "quarter"],
            ["one", "2021Q1"],
            ["two", "2021Q2"],
        ],
    }
)
assert list(book.sheet_names()) == ["Stuff", "Records", "Quarters"]

Unfortunately it does not.

E       AssertionError: assert ['Quarters', ...rds', 'Stuff'] == ['Stuff', 'Re...', 'Quarters']
E         At index 0 diff: 'Quarters' != 'Stuff'
E         Full diff:
E         - ['Stuff', 'Records', 'Quarters']
E         + ['Quarters', 'Records', 'Stuff']

I'd expect sheet_names to return the sheet names in the same order as the source dict.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions