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

Row._data as OrderedDict to allow element access by label #265

Closed
ms8r opened this issue Dec 29, 2016 · 2 comments
Closed

Row._data as OrderedDict to allow element access by label #265

ms8r opened this issue Dec 29, 2016 · 2 comments

Comments

@ms8r
Copy link

ms8r commented Dec 29, 2016

If headers are defined in a Dataset it would be helpful to allow element access within a row of the Dataset by column label in addition to index based access. Issue #22 suggested using namedtuples for this but --while acknowledging the general usefulness of such a feature-- was discarded because namedtuples would not support append, etc.

Implementing this via OrderedDicts should be possible though. It would require (it seems only in tablib/core.py on a first pass):

  • Row constructor to accept an additional headers argument
  • _set_headers to be augmented to update existing rows with new column labels
  • Changes to Row methods insert, __getitem__, __setitem__, and updates/changes to a few other special methods in Dataset and Row

It would introduce some overhead but given that Tablib is aimed at use cases "below" the Pandas level that might be acceptable and should not break the API.

I'm happy to give this a shot but --given that it will require changes in quite a few places in core.py-- would appreciate some feedback if (a) people still think that this would indeed be useful and (b) anyone sees a reason why doing this as outlined above is not a good idea (or may not even work at all...).

Many thanks!

@ms8r
Copy link
Author

ms8r commented Dec 29, 2016

Actually, OrderedDict is probably overkill... can simply keep reference to the Dataset that created/owns Row instance in that instance to have access to headers from within the Row instance...

@ms8r
Copy link
Author

ms8r commented Dec 31, 2016

Missed #158 when opening this one. Closing 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

1 participant