Repository: dask/dask

Issue:
Can't specify storage_options for bag.to_textfiles, dataframe.to_csv
The read functions allow specifying `storage_options` for things like AWS key/secret. The `to_parquet` function allows this as well.

However in other cases such as `bag.to_textfiles()` and `dataframe.to_csv()`, it is not possible to specify these options. It would be nice for there to be consistency, since there is no other way to specify some of the options at this time.


Discussion:

Resolving patch:
diff --git a/dask/bag/core.py b/dask/bag/core.py
--- a/dask/bag/core.py
+++ b/dask/bag/core.py
@@ -118,7 +118,8 @@ def optimize(dsk, keys, fuse_keys=None, rename_fused_keys=True, **kwargs):
 
 
 def to_textfiles(b, path, name_function=None, compression='infer',
-                 encoding=system_encoding, compute=True, get=None):
+                 encoding=system_encoding, compute=True, get=None,
+                 storage_options=None):
     """ Write bag to disk, one filename per partition, one line per element
 
     **Paths**: This will create one file for each partition in your bag. You
@@ -174,7 +175,7 @@ def to_textfiles(b, path, name_function=None, compression='infer',
     """
     from dask import delayed
     writes = write_bytes(b.to_delayed(), path, name_function, compression,
-                         encoding=encoding)
+                         encoding=encoding, **(storage_options or {}))
 
     # Use Bag optimizations on these delayed objects
     dsk = ensure_dict(delayed(writes).dask)
@@ -642,9 +643,10 @@ def unzip(self, n):
 
     @wraps(to_textfiles)
     def to_textfiles(self, path, name_function=None, compression='infer',
-                     encoding=system_encoding, compute=True, get=None):
+                     encoding=system_encoding, compute=True, get=None,
+                     storage_options=None):
         return to_textfiles(self, path, name_function, compression, encoding,
-                            compute, get=get)
+                            compute, get=get, storage_options=storage_options)
 
     def fold(self, binop, combine=None, initial=no_default, split_every=None):
         """ Parallelizable reduction
diff --git a/dask/dataframe/io/csv.py b/dask/dataframe/io/csv.py
--- a/dask/dataframe/io/csv.py
+++ b/dask/dataframe/io/csv.py
@@ -364,7 +364,7 @@ def _to_csv_chunk(df, **kwargs):
 
 
 def to_csv(df, filename, name_function=None, compression=None, compute=True,
-           get=None, **kwargs):
+           get=None, storage_options=None, **kwargs):
     """
     Store Dask DataFrame to CSV files
 
@@ -472,10 +472,12 @@ def to_csv(df, filename, name_function=None, compression=None, compute=True,
     decimal: string, default '.'
         Character recognized as decimal separator. E.g. use ',' for
         European data
+    storage_options: dict
+        Parameters passed on to the backend filesystem class.
     """
     values = [_to_csv_chunk(d, **kwargs) for d in df.to_delayed()]
     values = write_bytes(values, filename, name_function, compression,
-                         encoding=None)
+                         encoding=None, **(storage_options or {}))
 
     if compute:
         delayed(values).compute(get=get)


Test patch: