Skip to content

Commit

Permalink
switch from positional to names args in dataframe construction
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-rp committed Feb 29, 2024
1 parent 49e6aff commit 1d12f21
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions sources/arrow_pandas/example_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,23 @@
import pandas as pd
import pyarrow as pa

# this is example data, you will get this from somewhere on your resource function
EXAMPLE_ORDERS_DATA_FRAME = pd.DataFrame(
{
"order_id": [1, 2, 3],
"customer_id": [1, 2, 3],
"ordered_at": [
pendulum.DateTime(2021, 1, 1, 4, 5, 6),
pendulum.DateTime(2021, 1, 3, 4, 5, 6),
pendulum.DateTime(2021, 1, 6, 4, 5, 6),
],
"order_amount": [100.0, 200.0, 300.0],
}
)

EXAMPLE_CUSTOMERS_DATA_FRAME = pd.DataFrame(
{
"customer_id": [1, 2, 3],
"name": ["Alice", "Bob", "Charlie"],
"age": [25, 30, 35],
}
)


@dlt.resource(name="orders", write_disposition="append")
def orders() -> Generator[pd.DataFrame, None, None]:
# this is example data, you will get this from somewhere on your resource function
EXAMPLE_ORDERS_DATA_FRAME = pd.DataFrame(
data={
"order_id": [1, 2, 3],
"customer_id": [1, 2, 3],
"ordered_at": [
pendulum.DateTime(2021, 1, 1, 4, 5, 6),
pendulum.DateTime(2021, 1, 3, 4, 5, 6),
pendulum.DateTime(2021, 1, 6, 4, 5, 6),
],
"order_amount": [100.0, 200.0, 300.0],
}
)

# we can yield dataframes here, you will usually read them from a file or
# receive them from another library
yield EXAMPLE_ORDERS_DATA_FRAME
Expand All @@ -45,7 +37,14 @@ def orders() -> Generator[pd.DataFrame, None, None]:
def customers() -> Generator[pd.DataFrame, None, None]:
# we can yield arrow tables here, you will usually read them from a file or
# receive them from another library
EXAMPLE_CUSTOMERS_DATA_FRAME = pd.DataFrame(
data={
"customer_id": [1, 2, 3],
"name": ["Alice", "Bob", "Charlie"],
"age": [25, 30, 35],
}
)

# here we convert our dataframe to an arrow table, usually you would just yield the
# dataframe if you have it, this is for demonstration purposes
yield pa.Table.from_pandas(EXAMPLE_ORDERS_DATA_FRAME)
yield pa.Table.from_pandas(EXAMPLE_CUSTOMERS_DATA_FRAME)

0 comments on commit 1d12f21

Please sign in to comment.