Skip to content

[FEA] In-place DataFrame.drops()  #5664

Closed

Description

@madsbk

What

Support of in-place DataFrame.drops()

Motivation

Pandas and cuDF support in-place DataFrame.drops(), which is significant faster and less memory intensive than copying the whole DataFrame.

This can double the performance of a distributed merges in some cases: #5657

Additionally, a fast drops() operation can simplify common workflows: #5657 (comment)

Discussion

However as @mrocklin points out, we cannot support in-place as is because tasks in Dask may run twice or may run out-of-order so we generally cannot modify inputs of a task in-place.

As I see it, there is two approaches:

  • Making the drops() operation faster in cuDF, which is hard since the semantic of Pandas requires a full copy but could be done by using some kind of copy-on-write technique.
  • As suggested by @mrocklin, inject inplace=True in drop operations in Dask when it is safe. E.g., it is save when the drop is inside a blockwise operation where it doesn't affect the input of the blockwise operation. @rjzamora is working on this solution.

Activity

  1. rjzamora commented on Dec 3, 2019

    @rjzamora
    Member

    @mrocklin - I have a question about the kinds of "drop" tasks that can be safely modified to operate in-place.

    I understand that we would not want to modify data that is the direct input to the Blockwise subgraph containing the drop operation. You also mentioned that we would probably not want to modify a task that had multiple direct dependents. Is it dangerous when the dependents are also within the same subgraph, or just if the drop task has no dependents within the subgraph, but the larger Blockwise element has multiple dependents?

    For example, I am running a very simple test, and getting graph dependencies that look like this:

    subgraph-example

    Would it be safe to perform the drop "in place" for this sepcific example?

    For reference, the actual test looks like this:

    size = 4
    df = pd.DataFrame(
        {
            "a": np.random.permutation(np.arange(size)),
            "b": np.random.permutation(np.arange(size)),
        }
    )
    ddf = dd.from_pandas(df, npartitions=1)
    ddf["a"] = ddf["a"] + ddf["b"]
    ddf = ddf.drop(columns=["b"])
    ddf["a"] = ddf.a + 1
    graph_before = ddf.dask
    graph_after = optimize_blockwise(ddf.dask)
    graph_after_2 = optimize_drop(graph_after)
  2. mrocklin commented on Dec 3, 2019

    @mrocklin
    Member

    I think that it is likely safe if the drop node has many dependents (many tasks use the result of drop).

    The dangerous situtation, I think, is when the input to drop has other dependencies. In that situation it would matter if the drop was called first or second in the computation, which is hard for us to guarantee.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions