Skip to content

qsbase/qs2py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

qs2py

CI Python >=3.11 License: GPL-3.0-or-later

qs2py is a Python library for working with qdata, qs2, and standalone RDS files from the R ecosystem. Import it as qs2io.

qdata translation is implemented here in Python. qs2 and RDS translation currently use the rdata project for R object decoding/encoding, via a vendored fork for compatibility. If you only need RDS, you should look at rdata first.

Use Case

  • ✅ You move data back and forth between R and Python fairly often.
  • ✅ You mostly use R and have some qs2 or qdata data you want to open in Python.
  • ⚠️ You mainly have tabular data. This library can handle that, but if your workflow is table-first rather than R-interop-first, a dedicated format such as Parquet or DuckDB may be a better fit.
  • ❌ You primarily use Python and do not need compatibility with the R-side qs2 / qdata formats. In that case, the translation layer is mostly overhead.

Usage

  • qd_read / qd_save: read and write qdata format.
  • qs_read / qs_save: read and write qs2 format, translated to Python via rdata library.
  • rds_read / rds_save: read and write RDS format (via vendored rdata library).

Install

pip install qs2py

Quick Example

from qs2io import qd_read, qd_save, qs_read, qs_save, rds_read, rds_save

qd_obj = qd_read("data.qdata")
qd_pd = qd_read("data.qdata", dataframe_backend="pandas")
qd_pl = qd_read("data.qdata", dataframe_backend="polars")

qs_obj = qs_read("data.qs2")

rds_obj = rds_read("data.rds")

qd_save({"x": [1, 2, 3]}, "out.qdata")
qs_save({"x": [1, 2, 3]}, "out.qs2")
rds_save({"x": [1, 2, 3]}, "out.rds")

For qdata, dataframe output can be switched from pandas to polars.

Translation Notes

qdata files are decompressed and translated via code in this library. The translation spec is documented in:

qs2 uses the same outer format as qdata but object translation is delegated to the vendored rdata package.

Supported Behavior

At a high level, the qdata path supports:

  • numeric, logical, complex, character, raw, and NULL
  • nested lists
  • NumPy arrays, including masked integer/logical arrays
  • pandas and polars data frames
  • shape and label upgrades through dim, names, and dimnames
  • xarray.DataArray for labeled array round-tripping
  • date/time and duration mappings for the supported qdata subset

Limitations

  • qdata only covers the qdata-supported subset of R object types. It is not a general replacement for arbitrary R serialization.
  • qs2 / RDS translation uses rdata which may also have its own limitations.

About

qs2 Python interoperability

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors