From 9e63a1885d9d933f05a143d24869b05022f23814 Mon Sep 17 00:00:00 2001 From: Santhosh Ramaraj Date: Mon, 2 Feb 2026 10:34:08 +0530 Subject: [PATCH 1/3] feat: add example to append pandas df to DFS --- examples/dataframe/create_write_data.py | 45 +++++++++++++++++++++---- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/examples/dataframe/create_write_data.py b/examples/dataframe/create_write_data.py index a1580323..f8fa14d8 100644 --- a/examples/dataframe/create_write_data.py +++ b/examples/dataframe/create_write_data.py @@ -5,6 +5,10 @@ import pyarrow as pa # type: ignore except Exception: pa = None +try: + import pandas as pd # type: ignore +except Exception: + pd = None from nisystemlink.clients.core import HttpConfiguration from nisystemlink.clients.dataframe import DataFrameClient from nisystemlink.clients.dataframe.models import ( @@ -40,6 +44,11 @@ ) ) + +print(f"Created table with ID: {table_id}") + +print("Appending data to table...") + # Append via explicit AppendTableDataRequest (JSON) frame_request = DataFrame( data=[[str(i), str(random.random()), datetime.now().isoformat()] for i in range(3)] @@ -55,6 +64,7 @@ client.append_table_data(table_id, frame_direct) if pa is not None: + print("Appending data to table via Arrow RecordBatches...") # Append via single RecordBatch (Arrow) batch_single = pa.record_batch( [ @@ -79,9 +89,32 @@ ] client.append_table_data(table_id, batch_list) - # Mark end_of_data for the table - # Supply `None` and `end_of_data=True` - client.append_table_data(table_id, None, end_of_data=True) -else: - # If pyarrow not installed, flush via JSON path - client.append_table_data(table_id, None, end_of_data=True) + if pd is not None: + print("Appending data to table via Pandas DataFrame...") + # Append via DataFrame (Pandas) + df = pd.DataFrame( + { + "ix": [11, 12, 13], + "Float_Column": [0.6, 0.7, 0.8], + "Timestamp_Column": [datetime.now() for _ in range(3)], + } + ) + + # Optional - coerce df types to the dataframe table schema + df = df.astype( + { + "ix": "Int32", + "Float_Column": "float32", + "Timestamp_Column": "datetime64[ns]", + } + ) + + # convert Pandas DataFrame to Arrow RecordBatch + batch_single = pa.record_batch(df) + + client.append_table_data(table_id, batch_single) + +# Mark end_of_data for the table +# Supply `None` and `end_of_data=True` +print("Finished appending data.") +client.append_table_data(table_id, None, end_of_data=True) From dd444d6398f569a6ae059af1cb71e07ce1ff1087 Mon Sep 17 00:00:00 2001 From: Santhosh Ramaraj Date: Mon, 2 Feb 2026 12:04:29 +0530 Subject: [PATCH 2/3] refactor: use the constructor method to covert Pandas to PyArrow --- examples/dataframe/create_write_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/dataframe/create_write_data.py b/examples/dataframe/create_write_data.py index f8fa14d8..1469f9e9 100644 --- a/examples/dataframe/create_write_data.py +++ b/examples/dataframe/create_write_data.py @@ -110,7 +110,7 @@ ) # convert Pandas DataFrame to Arrow RecordBatch - batch_single = pa.record_batch(df) + batch_single = pa.RecordBatch.from_pandas(df) client.append_table_data(table_id, batch_single) From 7a004d484a2636c57ae4abe21139df8470809038 Mon Sep 17 00:00:00 2001 From: Santhosh Ramaraj Date: Mon, 2 Feb 2026 21:22:05 +0530 Subject: [PATCH 3/3] refactor: PR comments --- examples/dataframe/create_write_data.py | 43 ++++++++++++------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/examples/dataframe/create_write_data.py b/examples/dataframe/create_write_data.py index 1469f9e9..57c48f03 100644 --- a/examples/dataframe/create_write_data.py +++ b/examples/dataframe/create_write_data.py @@ -89,30 +89,29 @@ ] client.append_table_data(table_id, batch_list) - if pd is not None: - print("Appending data to table via Pandas DataFrame...") - # Append via DataFrame (Pandas) - df = pd.DataFrame( - { - "ix": [11, 12, 13], - "Float_Column": [0.6, 0.7, 0.8], - "Timestamp_Column": [datetime.now() for _ in range(3)], - } - ) - - # Optional - coerce df types to the dataframe table schema - df = df.astype( - { - "ix": "Int32", - "Float_Column": "float32", - "Timestamp_Column": "datetime64[ns]", - } - ) +if pa is not None and pd is not None: + print("Appending data to table via Pandas DataFrame...") + # Append via DataFrame (Pandas) + df = pd.DataFrame( + { + "ix": [11, 12, 13], + "Float_Column": [0.6, 0.7, 0.8], + "Timestamp_Column": [datetime.now() for _ in range(3)], + } + ) - # convert Pandas DataFrame to Arrow RecordBatch - batch_single = pa.RecordBatch.from_pandas(df) + # Optional - coerce df types to the dataframe table schema + df = df.astype( + { + "ix": "Int32", + "Float_Column": "float32", + "Timestamp_Column": "datetime64[ns]", + } + ) - client.append_table_data(table_id, batch_single) + # convert Pandas DataFrame to Arrow RecordBatch and append + record_batch = pa.RecordBatch.from_pandas(df) + client.append_table_data(table_id, record_batch) # Mark end_of_data for the table # Supply `None` and `end_of_data=True`