Skip to content

Dask fails when suppying filesystem or fs to dask.dataframe.read_parquet() #8677

Closed

Description

@th0ger

What happened:

When reading parquet files from Azure Blob Storage, we are providing an fsspec compatible filesystem to pyarrow (via the adlfs package).
However, in read_parquet() Dask will always determine an alternative filesystems via the path argument (such as s3://).
If one tries to provide a filesystem directly via args/kwargs, we end up with "multiple values for argument" errors.

What you expected to happen:

Either dataset={"filesystem": fs} and/or fs=fs should be valid syntax for read_parquet(), and this setting should overrule the fs determined automatically by Dask from the path.

Minimal Complete Verifiable Example:

## Real life fsspec example:
# from adlfs import AzureBlobFileSystem
# fs = AzureBlobFileSystem(account_name="myaccount", container_name="mycontainer", ...)

# Local fsspec example for debugging:
from fsspec.implementations.local import LocalFileSystem
fs = LocalFileSystem()

import dask.dataframe as dd
dd.read_parquet(
    path='foo.parquet',
    engine="pyarrow-dataset",
    dataset={"filesystem": fs}
    )

# >> TypeError: dataset() got multiple values for keyword argument 'filesystem'

dd.read_parquet(
    path='foo.parquet',
    engine="pyarrow-dataset",
    fs=fs
    )

# >> TypeError: read_metadata() got multiple values for argument 'fs'

Anything else we need to know?:

Current call to get_fs_token_paths() returning the authoritarian fs:

fs, _, paths = get_fs_token_paths(path, mode="rb", storage_options=storage_options)

Environment:

  • Dask version: 2022.1.1
  • Python version: 3.8
  • Operating System: Ubuntu 20.04.3 LTS
  • Install method (conda, pip, source): pipenv

Activity

  1. jsignell commented on Feb 9, 2022

    @jsignell
    Member

    It's not totally clear from your writeup if this is a regression or a request for an enhancement. Can you clarify if this used to work?

    Ping @martindurant and @rjzamora for fsspec/parquet expertise.

  2. rjzamora commented on Feb 9, 2022

    @rjzamora
    Member

    @th0ger - Can you please try specifying storage_options (as described here). I see that the read_parquet documentation on storage_options is a bit light - Perhaps we should improve the docstring a bit?

    It is indeed true that Dask will always consruct its own fsspec-based file-system object (no matter the backend engine).
    It is possible to override the file-open function at read time with open_file_options, but Dask will still use the internally-generated filesystem for initial metadata parsing. I'm sure it is possible to allow the backend to completely override file-system generation, but I'm not really convinced that the current behavior is a problem (but will be happy to reconsider if storage_options doesn't resolve your needs here).

  3. th0ger commented on Feb 10, 2022

    @th0ger
    ContributorAuthor

    OK, some background;
    I'm fairly new to working with both Arrow and Dask for interfacing with parquet.

    I started with pyarrow, which does not have native support for Azure blob storage (ADLSGen2), but it was very easy to get to work, using their very clear guide on using fsspec-compatible filesystems with Arrow. I also turned to their new Dataset API for better support on parquet partitions/predicate push down/projection.

    I needed an engine to perform joins between two parquet datasets (local and/or remote), so I turned to Dask...
    Support for arrow-dataset as backend - check! Support for passing kwargs to the backend - check!
    I though it would be a walk in the park, but oh my, it's hard to understand how to pass all these wrapped kwargs to different areas of the backend. And when you finally find out how to pass kwargs correctly - dask implements some traps on fsspec that doesn't really allow you to pass kwargs fully anyway... I have read more dask backend code now than I should've.

    @jsignell, in short, this is probably not a regression, but a feature request for something one would expect to work. But partly also a request for better documentation of what is (and isn't!) supported.

    I did not read the entire Dask documentation, but did read Connect to remote data, which states that both "adl://, abfs:// or az://" protocols are supported, but also states that "fsspec also provides other file systems". Since I was comming from an angle with pyarrow+fsspec working (and not a connection string authentication), I picked the fsspec option. That was clearly a mistake to follow that path.

    I tested your recommendations @rjzamora and the following works:

    dd.read_parquet(
        path='abfs://container/folder/file.parquet',
        engine="pyarrow-dataset",
        storage_options={"account_name": STORAGE_ACCOUNT, "account_key": STORAGE_KEY}
        )

    (Couldn't get client based auth to work with ADLSGen2 though; adlfs issue 299.)

    If you don't intend to change the behaviour stated in the issue, maybe:

    • Clarify in the the docs that fs and dataset={"filesystem": fs} must NOT be supplied in kwargs.
    • Raise an error that guides the user to the intended usage.
  4. rjzamora commented on Feb 11, 2022

    @rjzamora
    Member

    Thanks for writing this up @th0ger! Knowing about your experience is super valuable!

    Support for passing kwargs to the backend - check!

    Ah yes. This is a mess for a variety of reasons, but there is certainly no excuse for it to be quite as rough as it is. Cleaning this up (and addressing #8491) is on my short list.



    I though it would be a walk in the park, but oh my, it's hard to understand how to pass all these wrapped kwargs to different areas of the backend. And when you finally find out how to pass kwargs correctly - dask implements some traps on fsspec that doesn't really allow you to pass kwargs fully anyway... I have read more dask backend code now than I should've.

    

I completely agree with you. There is no reason someone should need to look at source code to figure out what to do. I do expect that I (and/or others) will be cleaning up kwarg-handling in the near future. It will also be nice when we finally drop pyarrow-legacy (and shed considerable tech debt in the process). However, what we absolutely need the most is clear documentation.

    If you don't intend to change the behaviour stated in the issue, maybe:

    • Clarify in the the docs that fs and dataset={"filesystem": fs} must NOT be supplied in kwargs.
    • Raise an error that guides the user to the intended usage.

    
I suspect that it will be challenging to allow the user to pass a filesystem to the backend, but this may be doable. Either way, we should be able to improve user experience with better documentation and warnings. Regarding actual behavior change: I will keep this experience in mind when I take a stab at #8491. Also, suggestions/contributions from other is very welcome. The parquet API has evolved a lot during the last few years to adapt to a variety of upstream changes and down-stream needs. It could be time to introduce breaking changes if we ultimately decide that it’s necessary.

  5. added
    documentation
    enhancement
    on Feb 17, 2022
  6. scharlottej13 commented on Feb 23, 2022

    @scharlottej13
    Contributor

    @rjzamora just checking in, what's the status on this issue? From your above comment it seems additional documentation and warnings would be helpful, should we open a separate issue for those changes? Thanks!

  7. rjzamora commented on Mar 2, 2022

    @rjzamora
    Member

    just checking in, what's the status on this issue? From your above comment it seems additional documentation and warnings would be helpful, should we open a separate issue for those changes? Thanks!

    Thanks for the ping and sorry for missing this @scharlottej13 ! I am hoping that I can clean up #8765 to make it easier to pass custom pyarrow.dataset.Dataset (or fastparquet.ParquetFile) options and improve the errors/warnings when unsupported arguments are passed. However, I do think a dedicated documentation issue makes sense - Hopefully #8772 covers what we want/need.

  8. added
    needs attention
    on Apr 4, 2022
  9. nastyakul commented on Mar 21, 2023

    @nastyakul

    Hi! I'm facing the same issue while using dd.read_csv with Azure-Datalake Gen2 Storage. Any tips how to resolve this?

  10. martindurant commented on Mar 21, 2023

    @martindurant
    Member

    Passing a filesystem to read_parquet, the purpose of this issue, has been implemented, so this issue should be closed.

    @nastyakul , not sure what problem you are facing or what behaviour you are missing - you might want to start a new issue with more details.

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

    documentationenhancementneeds attentionparquet

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions