Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

@ms8r

Description

@ms8r

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!

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