-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/mlflow dataset #6
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
base: master
Are you sure you want to change the base?
Changes from all commits
58ea683
6cb5472
8411863
573d7b4
c5da4b8
689cd6c
c9b00ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -31,7 +31,6 @@ def shard_parquet( | |||||||||||||||||
| AssertionError: If `rows_per_shard` or `row_group_size` are not strictly positive, | ||||||||||||||||||
| or if `rows_per_shard` is not perfectly divisible by `row_group_size`. | ||||||||||||||||||
| """ | ||||||||||||||||||
| # --- Input Validation --- | ||||||||||||||||||
| assert rows_per_shard > 0, "rows_per_shard must be greater than 0" | ||||||||||||||||||
| assert row_group_size > 0, "row_group_size must be greater than 0" | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -40,31 +39,25 @@ def shard_parquet( | |||||||||||||||||
| "rows_per_shard must be divisible by row_group_size" | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| # --- Setup Output Directory --- | ||||||||||||||||||
| output_dir = Path(output_dir) | ||||||||||||||||||
| output_dir.mkdir(parents=True, exist_ok=True) | ||||||||||||||||||
|
|
||||||||||||||||||
| # --- Read and Shard Process --- | ||||||||||||||||||
| with pq.ParquetFile(input_file) as parquet_file: | ||||||||||||||||||
| _logger.info(f"Total rows in source: {parquet_file.metadata.num_rows}") | ||||||||||||||||||
|
|
||||||||||||||||||
| # Initialize tracking variables | ||||||||||||||||||
| shard_idx = 0 | ||||||||||||||||||
| current_shard_rows = 0 | ||||||||||||||||||
| writer = None | ||||||||||||||||||
|
|
||||||||||||||||||
| try: | ||||||||||||||||||
| # Iterate through the source file in memory-efficient chunks (batches) | ||||||||||||||||||
| for batch in parquet_file.iter_batches(batch_size=row_group_size): | ||||||||||||||||||
| if writer is None: | ||||||||||||||||||
| out_path = output_dir / f"shard_{shard_idx:05d}.parquet" | ||||||||||||||||||
| writer = pq.ParquetWriter(out_path, batch.schema) | ||||||||||||||||||
|
|
||||||||||||||||||
| # Write the current batch | ||||||||||||||||||
| writer.write_batch(batch) | ||||||||||||||||||
| current_shard_rows += batch.num_rows | ||||||||||||||||||
|
|
||||||||||||||||||
| # Check if the current shard has reached its maximum capacity | ||||||||||||||||||
| if current_shard_rows >= rows_per_shard: | ||||||||||||||||||
| writer.close() | ||||||||||||||||||
| writer = None | ||||||||||||||||||
|
Comment on lines
61
to
63
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a critical bug here: when a shard reaches its capacity ( This causes two major issues:
We must increment
Suggested change
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that is not true, the code is there already |
||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| from rationai.mlkit.mlflow.parquet_dataset import ParquetDataset, from_parquet | ||
|
|
||
|
|
||
| __all__ = ["ParquetDataset", "from_parquet"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Python type hinting,
**kwargs: Tspecifies that all keyword arguments passed must be of typeT. Specifying**kwargs: dict[str, Any]means each individual keyword argument must be a dictionary, which is likely not the intention here. It should be typed as**kwargs: Any.