Skip to content

Update DataFrame expamle #59

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

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions example/pandas/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,32 @@
print(df)
print(df.describe())

# Also you can use proton settings in DataFrame API like using `execute` function. # noqa
# Here's an example with idempotent id.

# Reset stream
c.execute('drop stream if exists test')
c.execute(
"""create stream test (
year int16,
first_name string
)"""
)
settings = dict(use_numpy=True, idempotent_id='batch')

# Execute multiple insert operations.
for _ in range(5):
c.insert_dataframe(
'INSERT INTO "test" (year, first_name) VALUES',
df,
settings=settings,
)
time.sleep(3)

rv = c.execute('SELECT COUNT(*) FROM table(test)')
# Only the first times insert into the historical storage.
print(rv) # (4,)

# Converting query results to a variety of formats with dbapi
with connect('proton://localhost') as conn:
with conn.cursor() as cur:
Expand Down