Skip to content
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

added file checking and overwrite functionality to write #94

Merged
merged 6 commits into from
Sep 20, 2018
Merged
Changes from 3 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
24 changes: 22 additions & 2 deletions src/sink.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,31 @@ Base.size(sink::Sink, i::Integer) = size(sink.schema, i)


"""
write(filename::AbstractString, df::DataFrame)
write(filename::AbstractString, df::DataFrame; overwrite::Bool=false)

Write the dataframe `df` to the feather formatted file `filename`.

If the file `filename` already exists, an error will be thrown, unless `overwrite=true` in
which case the file will be deleted before writing.
"""
function write(filename::AbstractString, df::AbstractDataFrame)
function write(filename::AbstractString, df::AbstractDataFrame; overwrite::Bool=false)
if isfile(filename)
if !overwrite
throw(ArgumentError("File $filename already exists. Pass `overwrite=true` to overwrite."))
else
if Sys.iswindows()
try
rm(filename)
catch e
@error(string("Unable to delete file $filename. It's possible that it's ",
"already open and being used by this or another process."))
throw(e)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be rethrow?

end
else
rm(filename)
end
end
end
sink = Feather.Sink(filename, df)
Data.stream!(df, sink)
Data.close!(sink)
Expand Down