Skip to content

Commit 554e254

Browse files
committed
Merge branch 'parquet' into 'dev'
Add Apache Parquet export support See merge request mass-spectrometry/corems!229
2 parents 97b4cb7 + b635d54 commit 554e254

10 files changed

Lines changed: 651 additions & 24 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ As an open source project, CoreMS welcomes contributions of all forms. See the [
9999
- Pandas data frame (can be saved using pickle, h5, etc)
100100
- Text Files (.csv, tab separated .txt, etc)
101101
- Microsoft Excel (xlsx)
102+
- Apache Parquet (.parquet)
102103
- Automatic JSON for metadata storage and reuse
103104
- Self-containing Hierarchical Data Format (.hdf5) including raw data and time-series data-point for processed data-sets with all associated metadata stored as json attributes
104105

@@ -368,6 +369,8 @@ mass_spectrum_obj.to_csv("filename")
368369
mass_spectrum_obj.to_hdf("filename")
369370
# to pandas Datarame pickle
370371
mass_spectrum_obj.to_pandas("filename")
372+
# to parquet
373+
mass_spectrum_obj.to_parquet("filename")
371374
372375
# Extract data as a pandas Dataframe
373376
df = mass_spectrum_obj.to_dataframe()

corems/mass_spectra/factory/GC_Class.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,31 @@ def to_pandas(self, out_file_path, write_metadata=True, id_label="corems:"):
556556

557557
return out_file_path.with_suffix(".pkl")
558558

559+
def to_parquet(self, out_file_path, write_metadata=True, id_label="corems:"):
560+
"""Export the GC-MS data to a Parquet file.
561+
562+
Parameters
563+
----------
564+
out_file_path : str, pathlib.Path, or s3path.S3Path
565+
Path object containing the file location.
566+
write_metadata : bool, optional
567+
If True, write the metadata. Defaults to True.
568+
id_label : str, optional
569+
Label of the ID. Defaults to 'corems:'.
570+
571+
Notes
572+
-----
573+
Requires ``pyarrow`` (or ``fastparquet``) for pandas Parquet I/O.
574+
"""
575+
576+
if isinstance(out_file_path, str):
577+
out_file_path = Path(out_file_path)
578+
579+
exportMS = LowResGCMSExport(out_file_path, self)
580+
exportMS.to_parquet(id_label=id_label, write_metadata=write_metadata)
581+
582+
return out_file_path.with_suffix(".parquet")
583+
559584
def to_dataframe(self, id_label="corems:"):
560585
"""Export the GC-MS data to a Pandas dataframe.
561586

0 commit comments

Comments
 (0)