Skip to content

Initialize a Dataset from plain python dicts #491

Description

@JWCook

I'd like to be able to create a Dataset from plain python dicts. I read through just about everything in the docs and some of the code, and can't seem to find a way to do this directly.

What I'd like to be able to do is something like:

source_data = [
     {'column_1': 'value_1A',  'column_2':  'value_2A'},
     {'column_1': 'value_1B',  'column_2':  'value_2B'},
]
data = Dataset().load(*source_data)

Or maybe:

data = import_set(source_data, format='dict')

Current workarounds:

  • json.dumps the data first before loading
  • Register a custom format class
  • Separately add headers and row values:
    data = DataSet()
    data.headers = source_data[0].keys()
    data.extend([item.values() for item in source_data])

So I guess my questions are:

  • Is there currently a better way to do this?
  • If not, would you be interested in a PR for this?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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