-
Notifications
You must be signed in to change notification settings - Fork 140
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
Ensure FilePaths work #511
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Codecov Report
@@ Coverage Diff @@
## master #511 +/- ##
==========================================
- Coverage 84.52% 83.58% -0.94%
==========================================
Files 7 7
Lines 1402 1395 -7
==========================================
- Hits 1185 1166 -19
- Misses 217 229 +12
Continue to review full report at Codecov.
|
Looks good to me, only nice to have would be a test case with your example from the CR description:
|
src/utils.jl
Outdated
@@ -174,6 +174,8 @@ function getsource(source, use_mmap) | |||
return source | |||
elseif source isa Cmd | |||
return Base.read(source) | |||
elseif source isa AbstractPath | |||
return Base.read(Base.open(source)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, I don't love this because we're not matching the behavior when source
is a String, which I think should be consistent. When source
is a String and we have use_mmap
, then we Mmap.mmap
, otherwise, we make our own mmapped vector and copy the file contents into it. I'd rather rearrange to ensure strings and abstractpath sources are treated the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that some FilePaths can be mmap
s directly, in particular SystemPath
s
other cannot, like AWS3.S3Path
s
But I guess that can be fairly easily handled by treating SystemPath
s like strings,
and all other AbstractPaths
like Cmd
s etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SystemPath
s don't directly support mmap
and have to be opened first. We're also stuck using open on non-System Paths since that guarantees us the right type coming out of read
(S3Path
right now returns a String
).
Also why are we checking slurp(source isa IO ? source : open(String(source)))
after the elseif !isa(source, IO)
in this function?
The previous PR to add FilePaths support was It probably should have added FilePaths as a Test dependendcy, so that we would have been better at not breaking it |
f42d65a
to
6665922
Compare
ef5b140
to
0b2c95a
Compare
@@ -197,4 +202,9 @@ using CSV, Dates, WeakRefStrings, CategoricalArrays, Tables | |||
end | |||
|
|||
@test read(rd, String) == "col1,col2,col3\n1,4,7\n2,5,8\n3,6,9\n" | |||
|
|||
mktmpdir() do tmp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just as a heads up: this will be deprecated to mktempdir
in a future FilePathsBase release (rofinn/FilePathsBase.jl@v0.6.2...master). Just mentioning in case we want to bug @rofinn to release that change and increase the lower-bound on FPB compat here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mktmdir()
wasn't deprecated, it's just an alias for mktempdir(SystemPath)
now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
26bff2a
to
0bd1896
Compare
src/utils.jl
Outdated
elseif !isa(source, IO) | ||
m = Mmap.mmap(source) | ||
m = Mmap.mmap(source isa AbstractPath ? open(source) : source) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is effectively the same as
m = Mmap.mmap(source isa AbstractPath ? open(source) : source) | |
m = open(Mmap.mmap, source) |
since all Mmap.mmap(source::String)
does is basically open(Mmap.mmap, source)
anyway
My alternative dispatch based
I think this is the same as, and clear than the chain of conditionals |
Also, you'll probably need to rebase off current master head/tip to get windows CI fixes for travis. |
Bump; is there anything else @morris25 want to do on this? Any concerns @mattBrzezinski or @oxinabox? If this can be rebased, then I think CI should be clean and I'm happy to merge and do a new release. |
0bd1896
to
a024a72
Compare
That should be everything now! Sorry I didn't get back to this sooner |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, ship it!
@@ -175,27 +175,25 @@ function slurp(source) | |||
return final | |||
end | |||
|
|||
getsource(source::Vector{UInt8}, ::Any) = source |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just typing this solution up as you pushed your commit.
Thank you for making this 100% cleaner and easier to read!! 🚀 💯
The CSV.write docstring claims that it should work with FIlePaths
However, when I try to write to a Path I get
These changes should ensure CSV read/write functions work for any AbstractPath.