Skip to main content

dask chunked read_text on gzip file

Project description

Dask indexed gzip

|pypi-version| |travis| |coveralls|

An implementation compatible with `dask read_text`_ interface,
than can chunk a gzipped text file into several partitions,
thanks to an index, provided by `indexed_gzip`_

This is useful when your data resides in a big gzipped file,
yet you want to leverage dask parallelism capabilities.

Sample session


>>> import os
>>> import dask_igzip

.. initalization

>>> data_path = os.path.join(os.path.dirname(dask_igzip.__file__), "..", "test", "data")


>>> source = os.path.join(data_path, "sample.txt.gz")
>>> # 3 lines per chunk (obviously this is for demoing)
>>> bag = dask_igzip.read_text(source, chunk_size=3, encoding="utf-8")
>>> lines = bag.take(4, npartitions=2)
>>> print("".join(lines).strip())
a first sentence
a second sentence
a third sentence
a fourth sentence
>>> bag.str.upper().str.strip().compute()[8]
'LINE 9'

Why ?

Dask `read_text` creates a unique partition if you provide it with a gzip file.
This limitations comes from the fact that
there is no way to split the gzip file in a predictable yet coherent way.

This project provides an implementation where the gzip is indexed,
then lines positions are also indexed,
so that reading the text can be done by chunk (thus enabling parallelism).
On first run, indexes are saved on disk, so that subsequent runs are fast.

.. _`indexed_gzip`:
.. _`dask read_text`:

.. |pypi-version| image::
:alt: Latest PyPI version
.. |travis| image::
.. |coveralls| image::


The format is based on `Keep a Changelog`_
and this project tries to adhere to `Semantic Versioning`_.

.. _`Keep a Changelog`:
.. _`Semantic Versioning`:

0.2.0 - 2018-06-20


- read_text now accept a limit parameter to limit the global amount of lines to read


- incompatible format for lines index

0.1.0 - 2018-06-19


- initial release
- 100% code coverage

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dask-igzip-0.2.0.linux-x86_64.tar.gz (8.0 kB view hashes)

Uploaded source

Built Distribution

dask_igzip-0.2.0-py3-none-any.whl (7.7 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page