Skip to content
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

library re-orders columns when exporting content. #326

Closed
ghost opened this issue Feb 19, 2018 · 3 comments
Closed

library re-orders columns when exporting content. #326

ghost opened this issue Feb 19, 2018 · 3 comments

Comments

@ghost
Copy link

ghost commented Feb 19, 2018

Hello,

I've been using tablib indirectly through records to produce some Excel reports from a database, and I've noticed that while I add my content in a specific order, when exporting, the order of the columns is not the same as I added.

Looking at the documentation of tablib -- if the examples are not merely illustrative -- this should be noticeable, as for instance, when exporting to JSON, YAML, and CSV, the output "columns" are re-ordered differently for each format:

>>> print data.json
[
  {
    "last_name": "Adams",
    "age": 90,
    "first_name": "John"
  },
  {
    "last_name": "Ford",
    "age": 83,
    "first_name": "Henry"
  }
]

>>> print data.yaml
- {age: 90, first_name: John, last_name: Adams}
- {age: 83, first_name: Henry, last_name: Ford}

>>> print data.csv
first_name,last_name,age
John,Adams,90
Henry,Ford,83

I'd appreciate if this could be fixed in such way that output would always have the same structure as what was inputted.

Thanks

@kennethreitz

@lipi
Copy link

lipi commented Feb 22, 2018

Just noticed the same thing today, after importing data as a dictionary.

So instead of dictionary import I added headers as a list, then appended each row as a list. Export kept the column order after this.

So it is probably not the export itself, but the internal representation being a dictionary, where field order is not guaranteed.

@lipi
Copy link

lipi commented Feb 22, 2018

This issue is a duplicate of https://github.com/kennethreitz/tablib/issues/287

@iurisilvio
Copy link
Collaborator

Closed as duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants