Skip to content

Commit 83f0579

Browse files
authored
big_data.rst polars
1 parent 2e73737 commit 83f0579

1 file changed

Lines changed: 67 additions & 71 deletions

File tree

docs/day3/big_data.rst

Lines changed: 67 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -613,30 +613,26 @@ Exercise file formats (10 minutes)
613613
Computing efficiency with Python
614614
--------------------------------
615615

616-
Python is an interpreted language, and many features that make development rapid with Python are a result of that, with the price of reduced performance in many cases.
616+
Python is an interpreted language, and many features (dynamical typing, flexible data structures) that make development rapid with Python are a result of that, with the price of reduced performance in many cases.
617617

618-
- Dynamic typing
619-
- Flexible data structures
618+
There are some packages that are more efficient than Numpy and Pandas.
620619

621-
- There are some packages that are more efficient than Numpy and Pandas.
620+
- `SciPy <https://docs.scipy.org/doc/scipy/reference/>`_ is a library that builds on top of NumPy.
622621

623-
- `SciPy <https://docs.scipy.org/doc/scipy/reference/>`_ is a library that builds on top of NumPy.
624-
625-
- It contains a lot of interfaces to battle-tested numerical routines written in Fortran or C, as well as Python implementations of many common algorithms.
626-
- Reads NETCDF!
627-
628-
- `ENCCS course material <https://enccs.github.io/hpda-python/stack/#scipy>`_
622+
- It contains a lot of interfaces to battle-tested numerical routines written in Fortran or C, as well as Python implementations of many common algorithms.
623+
- Reads NETCDF!
624+
- `ENCCS course material <https://enccs.github.io/hpda-python/stack/#scipy>`_
629625

630626
Xarray package
631627
..............
632628

633-
- ``xarray`` is a Python package that builds on NumPy but adds labels to **multi-dimensional arrays**.
629+
``xarray`` is a Python package that builds on ``NumPy`` but adds labels to **multi-dimensional arrays**.
634630

635-
- introduces **labels in the form of dimensions, coordinates and attributes** on top of raw NumPy-like multidimensional arrays, which allows for a more intuitive, more concise, and less error-prone developer experience.
636-
- It also **borrows heavily from the Pandas package for labelled tabular data** and integrates tightly with dask for parallel computing.
631+
- **labels in the form of dimensions, coordinates and attributes** on top of raw NumPy-like multidimensional arrays, which allows for a more intuitive, more concise, and less error-prone developer experience.
632+
- **borrows from the Pandas package for labelled tabular data** and integrates tightly with ``dask`` for parallel computing.
637633

638-
- Xarray is particularly tailored to working with NetCDF files.
639-
- But work for another files as well
634+
- particularly tailored to working with NetCDF files.
635+
- work for another file formats as well
640636

641637
- Explore it a bit in the (optional) exercise below!
642638

@@ -645,42 +641,45 @@ Dask
645641

646642
How to use more resources than available?
647643

648-
.. image:: ../img/when-to-use-pandas.png
649-
:width: 600 px
644+
.. admonition:: Remember this image? ;-)
645+
:class: dropdown
646+
647+
.. image:: ../img/when-to-use-pandas.png
648+
:width: 600 px
650649

651650
Dask is very popular for data analysis and is used by a number of high-level
652-
Python libraries:
651+
Python libraries.
653652

654-
- Dask is composed of two parts:
653+
2 parts:
655654

656-
- **Dask Clusters**
657-
- Dynamic task scheduling optimized for computation. Similar to other workflow management systems, but optimized for interactive computational workloads.
658-
- `ENCCS course <https://enccs.github.io/hpda-python/dask/#dask-clusters>`_
659-
- **“Big Data” Collections**
660-
- Like parallel arrays, dataframes, and lists that extend common interfaces like NumPy, Pandas, or Python iterators to **larger-than-memory** or distributed environments. These parallel collections run on top of dynamic task schedulers.
661-
- `ENCCS course <https://enccs.github.io/hpda-python/dask/#dask-collections>`_
655+
- **Dask Clusters**
656+
- Dynamic task **scheduling** optimized for computation. Similar to other workflow management systems, but optimized for interactive computational workloads.
657+
- `ENCCS course <https://enccs.github.io/hpda-python/dask/#dask-clusters>`_
658+
- **“Big Data” Collections**
659+
- Like parallel arrays, dataframes, and lists that extend common interfaces like NumPy, Pandas, or Python iterators to **larger-than-memory** or distributed environments. These parallel collections run on top of dynamic task schedulers.
660+
- `ENCCS course <https://enccs.github.io/hpda-python/dask/#dask-collections>`_
662661

663662
Dask Collections
664663
::::::::::::::::
665664

666-
- Dask provides dynamic parallel task scheduling and three main high-level collections:
665+
Dask provides dynamic parallel task scheduling and three main high-level collections:
667666

668-
- ``dask.array``: Parallel **NumPy** arrays
669-
- scales NumPy (see also xarray)
670-
- ``dask.dataframe``: Parallel **Pandas** DataFrames
671-
- scales Pandas workflows
672-
- ``dask.bag``: Parallel Python **List**
673-
- https://enccs.github.io/hpda-python/dask/#dask-bag
667+
- ``dask.array``: Parallel **NumPy** arrays
668+
- scales NumPy (see also xarray)
669+
- ``dask.dataframe``: Parallel **Pandas** DataFrames
670+
- scales Pandas workflows
671+
- ``dask.bag``: Parallel Python **List**
672+
- https://enccs.github.io/hpda-python/dask/#dask-bag
674673

675674
.. seealso::
676675

677676
- `dask_ml package <https://ml.dask.org/>`_: Dask-ML provides scalable machine learning in Python using Dask alongside popular machine learning libraries like Scikit-Learn, XGBoost, and others.
678677
- `Dask.distributed <https://distributed.dask.org/en/stable/>`_: Dask.distributed is a lightweight library for distributed computing in Python. It extends both the concurrent.futures and dask APIs to moderate sized clusters.
679678

680-
dask.arrays
681-
^^^^^^^^^^^
679+
``dask.arrays``
680+
^^^^^^^^^^^^^^^
682681

683-
- A Dask array looks and feels a lot like a NumPy array.
682+
- A Dask array looks and feels a lot like a **NumPy array**.
684683
- However, a Dask array uses the so-called "lazy" execution mode, which allows one to
685684
- build up complex, large calculations symbolically
686685
- before turning them over the scheduler for execution.
@@ -721,25 +720,13 @@ Big file → split into chunks → parallel workers → results combined.
721720
Polars package
722721
..............
723722

724-
- ``polars`` is a Python package that presents itself as **Blazingly Fast DataFrame Library**
725-
- Utilizes all available cores on your machine.
726-
- Optimizes queries to reduce unneeded work/memory allocations.
727-
- Handles datasets much larger than your available RAM.
728-
- A consistent and predictable API.
729-
- Adheres to a strict schema (data-types should be known before running the query).
730-
731-
.. admonition:: Key features
732-
:class: dropdown
733-
734-
- Fast: Written from scratch in **Rust**
735-
- I/O: First class **support for all common data storage** layers
736-
- **Intuitive API**: Write your queries the way they were intended. Internally, there is a query optimizer.
737-
- Out of Core: **streaming** without requiring all your data to be in memory at the same time. I.e. **chunking**
738-
- **Parallel**: dividing the workload among the available CPU cores without any additional configuration.
739-
- GPU Support: Optionally run queries on **NVIDIA GPUs**
740-
- `Apache Arrow <https://arrow.apache.org/overview/>`_ support
723+
`Polars <https://pola.rs/>`_ is a Python package that presents itself as **Blazingly Fast DataFrame Library**
724+
- Utilizes all available cores on your machine.
725+
- Optimizes queries to reduce unneeded work/memory allocations.
726+
- Handles datasets much larger than your available RAM.
727+
- A consistent and predictable API.
728+
- Adheres to a strict schema (data-types should be known before running the query).
741729

742-
[`https://pola.rs/`](https://pola.rs/)
743730

744731
Exercises: Packages
745732
-------------------
@@ -966,9 +953,9 @@ Set up the environment
966953
But what happens if we use different chunk sizes?
967954
Try out with different chunk sizes:
968955

969-
- What happens if the dask chunks=(20000,20000)
956+
- What happens if the dask chunks=``(20000,20000)``
970957

971-
- What happens if the dask chunks=(250,250)
958+
- What happens if the dask chunks=``(250,250)``
972959

973960

974961
.. solution:: Choice of chunk size
@@ -987,25 +974,34 @@ Set up the environment
987974

988975
.. challenge:: (Optional) Xarray
989976

990-
- https://stackoverflow.com/questions/72155514/when-to-use-xarray-over-numpy-for-medium-rank-multidimensional-data
977+
- Read `when-to-use-xarray-over-numpy-for-medium-rank-multidimensional-data <https://stackoverflow.com/questions/72155514/when-to-use-xarray-over-numpy-for-medium-rank-multidimensional-data>`_
991978

992-
- Browse: https://docs.xarray.dev/en/v2024.11.0/getting-started-guide/why-xarray.html or change to more applicable version in drop-down menu to lower right.
979+
- Browse: <https://docs.xarray.dev/en/v2024.11.0/getting-started-guide/why-xarray.html> or change to more applicable version in drop-down menu to lower right.
993980
- find something interesting for you! Test some lines if you want to!
994981
- tips:
995-
- Pandas: https://docs.xarray.dev/en/v2024.11.0/getting-started-guide/faq.html#why-is-pandas-not-enough
996-
- gallery: https://docs.xarray.dev/en/v2024.11.0/gallery.html
997-
- ecosystems: https://docs.xarray.dev/en/v2024.11.0/ecosystem.html
998-
- Quick overview: https://docs.xarray.dev/en/v2024.11.0/getting-started-guide/quick-overview.html
999-
1000-
982+
- Pandas: <https://docs.xarray.dev/en/v2024.11.0/getting-started-guide/faq.html#why-is-pandas-not-enough>
983+
- gallery: <https://docs.xarray.dev/en/v2024.11.0/gallery.html>
984+
- ecosystems: <https://docs.xarray.dev/en/v2024.11.0/ecosystem.html>
985+
- Quick overview: <https://docs.xarray.dev/en/v2024.11.0/getting-started-guide/quick-overview.html>
1001986

1002987
.. challenge:: (Optional) Polars
1003988

1004-
- Browse: https://docs.pola.rs/.
989+
- Browse: <https://docs.pola.rs/>.
1005990
- find something interesting for you! Test some lines if you want to!
1006991
- tips:
1007992

1008-
- Check if your cluster has Polars!
993+
.. admonition:: Key features
994+
:class: dropdown
995+
996+
- Fast: Written from scratch in **Rust**
997+
- I/O: First class **support for all common data storage** layers
998+
- **Intuitive API**: Write your queries the way they were intended. Internally, there is a query optimizer.
999+
- Out of Core: **streaming** without requiring all your data to be in memory at the same time. I.e. **chunking**
1000+
- **Parallel**: dividing the workload among the available CPU cores without any additional configuration.
1001+
- GPU Support: Optionally run queries on **NVIDIA GPUs**
1002+
- `Apache Arrow <https://arrow.apache.org/overview/>`_ support
1003+
1004+
- Check if your cluster has Polars!
10091005

10101006
.. solution::
10111007

@@ -1038,7 +1034,7 @@ Set up the environment
10381034
10391035
- Load the module or install it in your present ``conda`` or ``venv`` environment
10401036

1041-
- Try the most interesting examples: https://docs.pola.rs/user-guide/getting-started/#reading-writing
1037+
- Try the most interesting examples: <https://docs.pola.rs/user-guide/getting-started/#reading-writing>
10421038

10431039

10441040
Summary
@@ -1055,13 +1051,13 @@ Summary
10551051
.. keypoints::
10561052

10571053
- Allocate more RAM by asking for
1058-
- Several cores
1059-
- Nodes will more RAM
1054+
- Several cores or request ``--mem``
1055+
- Nodes with more RAM
10601056
- Check job memory usage with ``sacct`` or ``sstat``. Check you documentation!
10611057
- File formats
10621058
- No format fits all requirements
10631059
- HDF5 and NetCDF good for Big data since it allows loading parts of the file into memory
1064-
- Store temporary data in local scratch ($SNIC_TMP).
1060+
- Store temporary data in local scratch ``($SNIC_TMP``).
10651061
- Packages
10661062
- xarray
10671063
- can deal with 3D-data and higher dimensions
@@ -1083,8 +1079,8 @@ Summary
10831079
ENCCS
10841080

10851081
- Dask for scalable analysis
1086-
- https://enccs.github.io/hpda-python/stack/
1087-
- https://enccs.github.io/hpda-python/dask/
1082+
- <https://enccs.github.io/hpda-python/stack/>
1083+
- <https://enccs.github.io/hpda-python/dask/>
10881084

10891085
- Too be included in the future?
10901086

0 commit comments

Comments
 (0)