Inspecting and optimizing the query plan
One feature that Polars provides that tools such as pandas don’t is the ability to inspect the query plan. Lazy evaluation in LazyFrames makes it possible for Polars to optimize the query plan and for us to inspect what it’s trying to do in a query.
In this recipe, we’ll look at how we can inspect and optimize the query plan.
Getting ready
You need the graphviz
library installed on your machine to use one of the methods for inspecting the query plan, which is the .show_graph()
method. However, the installation process is a bit different than other Python libraries because you need to add a path to graphviz
.
On Mac, the easiest way to do all that at once is using Homebrew, a package manager. You just need to run the following and the installation will be complete:
brew install graphviz
If you have a Windows machine or want to know more about the installation process, please refer to this documentation page...