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

data and metadata tables advice #24

Closed
joamatab opened this issue Jan 9, 2022 · 2 comments
Closed

data and metadata tables advice #24

joamatab opened this issue Jan 9, 2022 · 2 comments
Labels
question Further information is requested

Comments

@joamatab
Copy link

joamatab commented Jan 9, 2022

Thank you Josh for your work with pydbantic,

I want to store both data and metadata for my data

How do you recommend creating tables that can store pandas dataframes with arbitrary columns?

How about metadata where the metadata has some JSON fields?

@codemation codemation added the question Further information is requested label Jan 9, 2022
@codemation
Copy link
Owner

@joamatab thanks for opening an issue here for these questions.

  • Q - How do you recommend creating tables that can store pandas dataframes with arbitrary columns?
  • A - DataBaseModel s are a sub class of pydantic BaseModel and thus share the same constraints that you might face when creating a model. Fortunately custom classes and subsequently pandas DataFrame type objects can be used combined with the Config class attribute and arbitrary_types_allowed = True as documented here
from pandas import DataFrame
from pydbantic import DataBaseModel, PrimaryKey

class MyModel(DataBaseModel):
    id: str = PrimaryKey()
    frame: DataFrame

    class Config:
        arbitrary_types_allowed = True

In future releases I am considering applying a default arbitrary_types_allowed to True, to avoid the need to set this yourself. Since DataFrame type objects are serializable via pickle, they will be stored as bytes in the database within a Binary Field in the database.

  • Q: How about metadata where the metadata has some JSON fields?
  • A : If you expect the metadata fields to change or vary, then set the field type to dict, if it will always follow a set schema, consider creating a BaseModel for the metadata, both will be stored on Binary database fields ( of course de-serialized / serialized for you).

@codemation
Copy link
Owner

@joamatab - anything else on this issue?

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

No branches or pull requests

2 participants