Skip to content

Commit 3a6f2a3

Browse files
authored
Merge pull request #223 from posit-dev/fix-consistent-input-ingestion
fix: have consistent input ingestion for all classes/functions with a `data=` parameter
2 parents 6d9228b + d499767 commit 3a6f2a3

7 files changed

Lines changed: 580 additions & 17 deletions

File tree

pointblank/assistant.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ def assistant(
5959
`"ollama"`, and `"bedrock"`.
6060
data
6161
An optional data table to focus on during discussion with the PbA, which could be a
62-
DataFrame object or an Ibis table object. Read the *Supported Input Table Types* section for
63-
details on the supported table types.
62+
DataFrame object, an Ibis table object, a CSV file path, a Parquet file path, or a database
63+
connection string. Read the *Supported Input Table Types* section for details on the
64+
supported table types.
6465
tbl_name : str, optional
6566
The name of the data table. This is optional and is only used to provide a more detailed
6667
prompt to the PbA.
@@ -142,9 +143,13 @@ def assistant(
142143
- PostgreSQL table (`"postgresql"`)*
143144
- SQLite table (`"sqlite"`)*
144145
- Parquet table (`"parquet"`)*
146+
- CSV files (string path or `pathlib.Path` object with `.csv` extension)
147+
- Parquet files (string path, `pathlib.Path` object, glob pattern, directory with `.parquet`
148+
extension, or partitioned dataset)
149+
- Database connection strings (URI format with optional table specification)
145150
146151
The table types marked with an asterisk need to be prepared as Ibis tables (with type of
147-
`ibis.expr.types.relations.Table`). Furthermore, using `preview()` with these types of tables
152+
`ibis.expr.types.relations.Table`). Furthermore, using `assistant()` with these types of tables
148153
requires the Ibis library (`v9.5.0` or above) to be installed. If the input table is a Polars or
149154
Pandas DataFrame, the availability of Ibis is not needed.
150155
"""
@@ -174,6 +179,23 @@ def assistant(
174179

175180
# If a dataset is provided, generate a table summary in JSON format
176181
if data is not None:
182+
# Import processing functions from validate module
183+
from pointblank.validate import (
184+
_process_connection_string,
185+
_process_csv_input,
186+
_process_parquet_input,
187+
)
188+
189+
# Process input data to handle different data source types
190+
# Handle connection string input (e.g., "duckdb:///path/to/file.ddb::table_name")
191+
data = _process_connection_string(data)
192+
193+
# Handle CSV file input (e.g., "data.csv" or Path("data.csv"))
194+
data = _process_csv_input(data)
195+
196+
# Handle Parquet file input (e.g., "data.parquet", "data/*.parquet", "data/")
197+
data = _process_parquet_input(data)
198+
177199
scan = DataScan(data=data)
178200

179201
tbl_type: str = scan.profile.implementation.name.lower()

pointblank/compare.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@
1010

1111
class Compare:
1212
def __init__(self, a: IntoFrame, b: IntoFrame) -> None:
13+
# Import processing functions from validate module
14+
from pointblank.validate import (
15+
_process_connection_string,
16+
_process_csv_input,
17+
_process_parquet_input,
18+
)
19+
20+
# Process input data for table a
21+
a = _process_connection_string(a)
22+
a = _process_csv_input(a)
23+
a = _process_parquet_input(a)
24+
25+
# Process input data for table b
26+
b = _process_connection_string(b)
27+
b = _process_csv_input(b)
28+
b = _process_parquet_input(b)
29+
1330
self.a: IntoFrame = a
1431
self.b: IntoFrame = b
1532

pointblank/datascan.py

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ class DataScan:
5656
Parameters
5757
----------
5858
data
59-
The data to scan and summarize.
59+
The data to scan and summarize. This could be a DataFrame object, an Ibis table object,
60+
a CSV file path, a Parquet file path, or a database connection string.
6061
tbl_name
6162
Optionally, the name of the table could be provided as `tbl_name`.
6263
@@ -122,6 +123,23 @@ class DataScan:
122123

123124
# TODO: This needs to be generically typed at the class level, ie. DataScan[T]
124125
def __init__(self, data: IntoFrameT, tbl_name: str | None = None) -> None:
126+
# Import processing functions from validate module
127+
from pointblank.validate import (
128+
_process_connection_string,
129+
_process_csv_input,
130+
_process_parquet_input,
131+
)
132+
133+
# Process input data to handle different data source types
134+
# Handle connection string input (e.g., "duckdb:///path/to/file.ddb::table_name")
135+
data = _process_connection_string(data)
136+
137+
# Handle CSV file input (e.g., "data.csv" or Path("data.csv"))
138+
data = _process_csv_input(data)
139+
140+
# Handle Parquet file input (e.g., "data.parquet", "data/*.parquet", "data/")
141+
data = _process_parquet_input(data)
142+
125143
as_native = nw.from_native(data)
126144

127145
if as_native.implementation.name == "IBIS" and as_native._level == "lazy":
@@ -514,8 +532,9 @@ def col_summary_tbl(data: FrameT | Any, tbl_name: str | None = None) -> GT:
514532
Parameters
515533
----------
516534
data
517-
The table to summarize, which could be a DataFrame object or an Ibis table object. Read the
518-
*Supported Input Table Types* section for details on the supported table types.
535+
The table to summarize, which could be a DataFrame object, an Ibis table object, a CSV
536+
file path, a Parquet file path, or a database connection string. Read the *Supported Input
537+
Table Types* section for details on the supported table types.
519538
tbl_name
520539
Optionally, the name of the table could be provided as `tbl_name=`.
521540
@@ -535,6 +554,10 @@ def col_summary_tbl(data: FrameT | Any, tbl_name: str | None = None) -> GT:
535554
- PostgreSQL table (`"postgresql"`)*
536555
- SQLite table (`"sqlite"`)*
537556
- Parquet table (`"parquet"`)*
557+
- CSV files (string path or `pathlib.Path` object with `.csv` extension)
558+
- Parquet files (string path, `pathlib.Path` object, glob pattern, directory with `.parquet`
559+
extension, or partitioned dataset)
560+
- Database connection strings (URI format with optional table specification)
538561
539562
The table types marked with an asterisk need to be prepared as Ibis tables (with type of
540563
`ibis.expr.types.relations.Table`). Furthermore, using `col_summary_tbl()` with these types of
@@ -566,5 +589,22 @@ def col_summary_tbl(data: FrameT | Any, tbl_name: str | None = None) -> GT:
566589
```
567590
"""
568591

592+
# Import processing functions from validate module
593+
from pointblank.validate import (
594+
_process_connection_string,
595+
_process_csv_input,
596+
_process_parquet_input,
597+
)
598+
599+
# Process input data to handle different data source types
600+
# Handle connection string input (e.g., "duckdb:///path/to/file.ddb::table_name")
601+
data = _process_connection_string(data)
602+
603+
# Handle CSV file input (e.g., "data.csv" or Path("data.csv"))
604+
data = _process_csv_input(data)
605+
606+
# Handle Parquet file input (e.g., "data.parquet", "data/*.parquet", "data/")
607+
data = _process_parquet_input(data)
608+
569609
scanner = DataScan(data=data, tbl_name=tbl_name)
570610
return scanner.get_tabular_report()

0 commit comments

Comments
 (0)