8000 Fix docs explaining write modes for Luigi Targets. Closes #2783 by guidopetri · Pull Request #2931 · spotify/luigi · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix docs explaining write modes for Luigi Targets. Closes #2783 #2931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions doc/tasks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,31 @@ An example:
)
)

It's useful to note that if you're writing to a binary file, Luigi automatically
strips the ``'b'`` flag due to how atomic writes/reads work. In order to write a binary
file, such as a pickle file, you should instead use ``format=Nop`` when calling
LocalTarget. Following the above example:

.. code:: python

class GenerateWords(luigi.Task):

def output(self):
return luigi.LocalTarget('words.pckl', format=Nop)

def run(self):
import pickle

# write a dummy list of words to output file
words = [
'apple',
'banana',
'grapefruit'
]

with self.output().open('w') as f:
pickle.dump(words, f)

.. _Task.input:

Task.input
Expand Down
3 changes: 2 additions & 1 deletion luigi/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ def open(self, mode):

:param str mode: the mode `r` opens the FileSystemTarget in read-only mode, whereas `w` will
open the FileSystemTarget in write mode. Subclasses can implement
additional options.
additional options. Using `b` is not supported; initialize with
`format=Nop` instead.
"""
pass

Expand Down
0