mldataforge 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mldataforge-0.0.1/.gitignore +3 -0
- mldataforge-0.0.1/LICENSE +21 -0
- mldataforge-0.0.1/PKG-INFO +20 -0
- mldataforge-0.0.1/README.md +2 -0
- mldataforge-0.0.1/mldataforge/__main__.py +12 -0
- mldataforge-0.0.1/mldataforge/commands/__init__.py +3 -0
- mldataforge-0.0.1/mldataforge/commands/convert/__init__.py +11 -0
- mldataforge-0.0.1/mldataforge/commands/convert/parquet/__init__.py +11 -0
- mldataforge-0.0.1/mldataforge/commands/convert/parquet/jsonl.py +55 -0
- mldataforge-0.0.1/pyproject.toml +37 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 schneiderkamplab
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: mldataforge
|
3
|
+
Version: 0.0.1
|
4
|
+
Summary: swiss army knife of scripts for transforming and processing datasets for machine learning.
|
5
|
+
Project-URL: Homepage, https://github.com/schneiderkamplab/mldataforge
|
6
|
+
Project-URL: Bug Tracker, https://github.com/schneiderkamplab/mldataforge/issues
|
7
|
+
Author: Peter Schneider-Kamp
|
8
|
+
License-File: LICENSE
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
10
|
+
Classifier: Operating System :: OS Independent
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
12
|
+
Requires-Python: >=3.12
|
13
|
+
Requires-Dist: click
|
14
|
+
Requires-Dist: datasets
|
15
|
+
Requires-Dist: mltiming
|
16
|
+
Requires-Dist: pygz
|
17
|
+
Description-Content-Type: text/markdown
|
18
|
+
|
19
|
+
# mldatasets
|
20
|
+
swiss army knife of scripts for transforming and processing datasets for machine learning
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/bin/env python
|
2
|
+
import atexit
|
3
|
+
import click
|
4
|
+
from datasets import load_dataset
|
5
|
+
from mltiming import timing
|
6
|
+
import os
|
7
|
+
from pygz import PigzFile
|
8
|
+
from shutil import which
|
9
|
+
import tempfile
|
10
|
+
|
11
|
+
def create_temp_file():
|
12
|
+
# Create a named temp file, don't delete right away
|
13
|
+
temp = tempfile.NamedTemporaryFile(delete=False)
|
14
|
+
temp_name = temp.name
|
15
|
+
# Close so others can open it again without conflicts (especially on Windows)
|
16
|
+
temp.close()
|
17
|
+
|
18
|
+
# Schedule its deletion at exit
|
19
|
+
atexit.register(_cleanup_file, temp_name)
|
20
|
+
|
21
|
+
return temp_name
|
22
|
+
|
23
|
+
def _cleanup_file(file_path):
|
24
|
+
try:
|
25
|
+
os.remove(file_path)
|
26
|
+
except OSError:
|
27
|
+
pass
|
28
|
+
|
29
|
+
@click.command()
|
30
|
+
@click.argument("parquet_file", type=click.Path(exists=True))
|
31
|
+
@click.argument("output_file", type=click.Path(exists=False), required=False)
|
32
|
+
@click.option("--compression", default="infer", type=click.Choice(["none", "infer", "pigz", "gzip", "bz2", "xz"]), help="Compress the output JSONL file (default: infer; pigz for parallel gzip).")
|
33
|
+
@click.option("--threads", default=64, help="Number of processes to use for pigz compression (default: 64).")
|
34
|
+
@click.option("--overwrite", is_flag=True, help="Overwrite existing JSONL files.")
|
35
|
+
def jsonl(parquet_file, output_file, compression, threads, overwrite):
|
36
|
+
if os.path.exists(output_file) and not overwrite:
|
37
|
+
raise click.ClickException(f"Output file {output_file} already exists. Use --overwrite to overwrite.")
|
38
|
+
with timing(message=f"Loading from {parquet_file}"):
|
39
|
+
ds = load_dataset("parquet", data_files=parquet_file)
|
40
|
+
orig_output_file = None
|
41
|
+
if compression == "none":
|
42
|
+
compression = None
|
43
|
+
elif compression == "infer":
|
44
|
+
if output_file.endswith(".gz") and which("pigz") is not None:
|
45
|
+
compression = "pigz"
|
46
|
+
if compression == "pigz":
|
47
|
+
compression = None
|
48
|
+
orig_output_file = output_file
|
49
|
+
output_file = create_temp_file()
|
50
|
+
with timing(message=f"Saving to {output_file} with compression {compression}"):
|
51
|
+
ds["train"].to_json(output_file, orient="records", lines=True, compression=compression)
|
52
|
+
if orig_output_file is not None:
|
53
|
+
with timing(message=f"Compressing {output_file} to {orig_output_file} with pigz using {threads} threads"):
|
54
|
+
with open(output_file, "rt") as f_in, PigzFile(f"{orig_output_file}.gz", "wt", threads=threads) as f_out:
|
55
|
+
f_out.write(f_in.read())
|
@@ -0,0 +1,37 @@
|
|
1
|
+
[build-system]
|
2
|
+
requires = ["hatchling"]
|
3
|
+
build-backend = "hatchling.build"
|
4
|
+
|
5
|
+
[project]
|
6
|
+
name = "mldataforge"
|
7
|
+
version = "0.0.1"
|
8
|
+
authors = [
|
9
|
+
{ name = "Peter Schneider-Kamp" }
|
10
|
+
]
|
11
|
+
|
12
|
+
description = "swiss army knife of scripts for transforming and processing datasets for machine learning."
|
13
|
+
readme = "README.md"
|
14
|
+
requires-python = ">=3.12"
|
15
|
+
classifiers = [
|
16
|
+
"Programming Language :: Python :: 3",
|
17
|
+
"License :: OSI Approved :: MIT License",
|
18
|
+
"Operating System :: OS Independent",
|
19
|
+
]
|
20
|
+
|
21
|
+
dependencies = [
|
22
|
+
'click',
|
23
|
+
'datasets',
|
24
|
+
'mltiming',
|
25
|
+
'pygz'
|
26
|
+
]
|
27
|
+
|
28
|
+
[project.urls]
|
29
|
+
"Homepage" = "https://github.com/schneiderkamplab/mldataforge"
|
30
|
+
"Bug Tracker" = "https://github.com/schneiderkamplab/mldataforge/issues"
|
31
|
+
|
32
|
+
[tool.hatch.build]
|
33
|
+
include = [
|
34
|
+
'mldataforge',
|
35
|
+
'LICENSE',
|
36
|
+
'README.md',
|
37
|
+
]
|