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

Add pyarrow date and timestamp type conversion from pydantic #576

Merged
merged 6 commits into from
Oct 17, 2023

Conversation

prrao87
Copy link
Contributor

@prrao87 prrao87 commented Oct 17, 2023

Closes #575 -- Missing pydantic types in python are properly converted to their pyarrow equivalents.

  • Convert python date type to pyarrow pa.date32() type
  • Convert python datetime type to pyarrow pa.timestamp('us') type
  • Tests passing on my end 👍🏼

It works great for both regular dates and datetimes.

class Content(LanceModel):
    text: str
    created: date
    timestamp: datetime

db = lancedb.connect("test")
tbl = db.create_table("test", schema=pydantic_to_schema(Content), mode="overwrite")

# Add some data
data = Content(text="Hello", created=date.today(), timestamp=datetime.now())
tbl.add([data])

# Query data
print(tbl.search().to_pandas())

Gives:

    text     created                  timestamp
0  Hello  2023-10-16 2023-10-16 22:37:10.499493

Copy link
Contributor

@changhiskhan changhiskhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great thanks!

@changhiskhan changhiskhan merged commit 86efb11 into lancedb:main Oct 17, 2023
6 checks passed
raghavdixit99 pushed a commit to raghavdixit99/lancedb that referenced this pull request Apr 5, 2024
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

Successfully merging this pull request may close these issues.

Missing pyarrow type conversion for date and datetime
2 participants