<jupyter_start><jupyter_text>Using Dask EntitySets (BETA)<jupyter_code>.. note::
    Support for Dask EntitySets is still in Beta. While the key functionality has been implemented, development is ongoing to add the remaining functionality.

    All planned improvements to the Featuretools/Dask integration are `documented on Github <https://github.com/alteryx/featuretools/issues?q=is%3Aopen+is%3Aissue+label%3ADask>`_. If you see an open issue that is important for your application, please let us know by upvoting or commenting on the issue. If you encounter any errors using Dask dataframes in EntitySets, or find missing functionality that does not yet have an open issue, please create a `new issue on Github <https://github.com/alteryx/featuretools/issues>`_.<jupyter_output><empty_output><jupyter_text>Creating a feature matrix from a very large dataset can be problematic if the underlying pandas dataframes that make up the EntitySet cannot easily fit in memory. To help get around this issue, Featuretools supports creating `EntitySet` objects from Dask dataframes. A Dask `EntitySet` can then be passed to `featuretools.dfs` or `featuretools.calculate_feature_matrix` to create a feature matrix, which will be returned as a Dask dataframe. In addition to working on larger than memory datasets, this approach also allows users to take advantage of the parallel and distributed processing capabilities offered by Dask.This guide will provide an overview of how to create a Dask `EntitySet` and then generate a feature matrix from it. If you are already familiar with creating a feature matrix starting from pandas DataFrames, this process will seem quite familiar, as there are no differences in the process. There are, however, some limitations when using Dask dataframes, and those limitations are reviewed in more detail below. Creating EntitySetsFor this example, we will create a very small pandas DataFrame and then convert this into a Dask DataFrame to use in the remainder of the process. Normally when using Dask, you would just read your data directly into a Dask DataFrame without the intermediate step of using pandas.<jupyter_code>import featuretools as ft
import pandas as pd
import dask.dataframe as dd

id = [0, 1, 2, 3, 4]
values = [12, -35, 14, 103, -51]
df = pd.DataFrame({"id": id, "values": values})
dask_df = dd.from_pandas(df, npartitions=2)

dask_df<jupyter_output><empty_output><jupyter_text>Now that we have our Dask DataFrame, we can start to create the `EntitySet`. Inferring Woodwork logical types for the columns in a Dask dataframe can be computationally expensive. To avoid this expense, logical type inference can be skipped by supplying a dictionary of logical types using the `logical_types` parameter when calling `es.add_dataframe()`. Logical types can be specified as Woodwork LogicalType classes, or their equivalent string representation. For more information refer to the [Woodwork Typing in Featuretools](../getting_started/woodwork_types.ipynb) guide.Aside from supplying the logical types, the rest of the process of creating an `EntitySet` is the same as if we were using pandas DataFrames.<jupyter_code>from woodwork.logical_types import Double, Integer

es = ft.EntitySet(id="dask_es")
es = es.add_dataframe(dataframe_name="dask_input_df",
                      dataframe=dask_df,
                      index="id",
                      logical_types={"id": Integer, "values": Double})

es<jupyter_output><empty_output><jupyter_text>Notice that when we print our `EntitySet`, the number of rows for the DataFrame named `dask_input_df` is returned as a Dask `Delayed` object. This is because obtaining the length of a Dask DataFrame may require an expensive compute operation to sum up the lengths of all the individual partitions that make up the DataFrame and that operation is not performed by default. Running DFSWe can pass the `EntitySet` we created above to `featuretools.dfs` in order to create a feature matrix. If the `EntitySet` we pass to `dfs` is made of Dask DataFrames, the feature matrix we get back will be a Dask DataFrame.<jupyter_code>feature_matrix, features = ft.dfs(entityset=es,
                                  target_dataframe_name="dask_input_df",
                                  trans_primitives=["negate"],
                                  max_depth=1)
feature_matrix<jupyter_output><empty_output><jupyter_text>This feature matrix can be saved to disk or computed and brought into memory, using the appropriate Dask DataFrame methods.<jupyter_code>fm_computed = feature_matrix.compute()
fm_computed<jupyter_output><empty_output><jupyter_text>While this is a simple example to illustrate the process of using Dask DataFrames with Featuretools, this process will also work with an `EntitySet` containing multiple dataframes, as well as with aggregation primitives. LimitationsThe key functionality of Featuretools is available for use with a Dask `EntitySet`, and work is ongoing to add the remaining functionality that is available when using a pandas `EntitySet`. There are, however, some limitations to be aware of when creating a Dask `Entityset` and then using it to generate a feature matrix. The most significant limitations are reviewed in more detail in this section.<jupyter_code>.. note::
    If the limitations of using a Dask ``EntitySet`` are problematic for your problem, you may still be able to compute a larger-than-memory feature matrix by partitioning your data as described in :doc:`performance`.<jupyter_output><empty_output><jupyter_text>Supported PrimitivesWhen creating a feature matrix from a Dask `EntitySet`, only certain primitives can be used. Primitives that rely on the order of the entire DataFrame or require an entire column for computation are currently not supported when using a Dask `EntitySet`. Multivariable and time-dependent aggregation primitives also are not currently supported.To obtain a list of the primitives that can be used with a Dask `EntitySet`, you can call `featuretools.list_primitives()`. This will return a table of all primitives. Any primitive that can be used with a Dask `EntitySet` will have a value of `True` in the `dask_compatible` column.<jupyter_code>primitives_df = ft.list_primitives()
dask_compatible_df = primitives_df[primitives_df["dask_compatible"] == True]
dask_compatible_df.head()
dask_compatible_df.tail()<jupyter_output><empty_output><jupyter_text>Primitive LimitationsAt this time, custom primitives created with `featuretools.primitives.make_trans_primitive()` or `featuretools.primitives.make_agg_primitive()` cannot be used for running deep feature synthesis on a Dask `EntitySet`. While it is possible to create custom primitives for use with a Dask `EntitySet` by extending the proper primitive class, there are several potential problems in doing so, and those issues are beyond the scope of this guide. DataFrame LimitationsFeaturetools stores the DataFrames that make up an EntitySet as Woodwork DataFrames which include additional typing information about the columns that are in the DataFrame. When adding a DataFrame to an `EntitySet`, Woodwork will attempt to infer the logical types for any columns that do not have a logical type defined. This inference process can be quite expensive for Dask DataFrames. In order to skip type inference and speed up the process of adding a Dask DataFrame to an `EntitySet`, users can specify the logical type to use for each column in the DataFrame. A list of available logical types can be obtained by running ``featuretools.list_logical_types()``. To learn more about the limitations of a Dask dataframe with Woodwork typing, see the [Woodwork guide on Dask dataframes](https://woodwork.alteryx.com/en/stable/guides/using_woodwork_with_dask_and_koalas.htmlDask-DataFrame-Example).By default, Woodwork checks that pandas DataFrames have unique index values. Because performing this same check with Dask would require an expensive compute operation, this check is not performed when adding a Dask DataFrame to an `EntitySet`. When using Dask DataFrames, users must ensure that the supplied index values are unique.When using a pandas DataFrames, the ordering of the underlying DataFrame rows is maintained by Featuretools. For a Dask DataFrame, the ordering of the DataFrame rows is not guaranteed, and Featuretools does not attempt to maintain row order. If ordering is important, close attention must be paid to any output to avoid issues. EntitySet LimitationsWhen creating a Featuretools `EntitySet` that will be made of Dask DataFrames, all of the DataFrames used to create the `EntitySet` must be of the same type, either all Dask DataFrames or all pandas DataFrames. Featuretools does not support creating an `EntitySet` containing a mix of Dask and pandas DataFrames.Additionally, ``EntitySet.add_interesting_values()`` cannot be used in Dask EntitySets to find interesting values; however, it can be used set a column's interesting values with the `values` parameter.<jupyter_code>values_dict = {'values': [12, 103]}
es.add_interesting_values(dataframe_name='dask_input_df', values=values_dict)

es['dask_input_df'].ww.columns['values'].metadata<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.05302042590178183, 'fraction_numerical': 0.002824858757062147, 'mean_word_length': 5.153074866310161, 'pattern_counts': {'":': 4, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '444989', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 2381, 'n_tokens_neox': 2272, 'n_words': 1184, 'path': 'docs/source/guides/using_dask_entitysets.ipynb', 'repo_name': 'tvdboom/featuretools', 'size': '9204'}