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

Relax type constraints on filenames #394

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 7 additions & 7 deletions src/CSV.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ end
const EMPTY_TYPEMAP = Dict{Type, Type}()

"""
CSV.File(source::Union{String, IO}; kwargs...) => CSV.File
CSV.File(source; kwargs...) => CSV.File

Read a csv input (a filename given as a String, or any other IO source), returning a `CSV.File` object.
Opens the file and uses passed arguments to detect the number of columns and column types.
Expand Down Expand Up @@ -96,7 +96,7 @@ Supported keyword arguments include:
* `strict::Bool=false`: whether invalid values should throw a parsing error or be replaced with missing values
* `silencewarnings::Bool=false`: whether invalid value warnings should be silenced (requires `strict=false`)
"""
function File(source::Union{String, IO};
function File(source;
# file options
# header can be a row number, range of rows, or actual string vector
header::Union{Integer, UnitRange{Int}, Vector}=1,
Expand Down Expand Up @@ -132,7 +132,7 @@ function File(source::Union{String, IO};
debug::Bool=false,
kw...)

isa(source, AbstractString) && (isfile(source) || throw(ArgumentError("\"$source\" is not a valid file")))
!isa(source, IO) && (isfile(source) || throw(ArgumentError("\"$source\" is not a valid file")))
(types !== nothing && any(x->!isconcretetype(x) && !(x isa Union), types isa AbstractDict ? values(types) : types)) && throw(ArgumentError("Non-concrete types passed in `types` keyword argument, please provide concrete types for columns: $types"))
io = getio(source, use_mmap)

Expand Down Expand Up @@ -211,9 +211,9 @@ include("filedetection.jl")
include("typedetection.jl")
include("tables.jl")

getio(str::String, use_mmap) = use_mmap ? IOBuffer(Mmap.mmap(str)) : Parsers.BufferedIO(open(str))
getio(filename, use_mmap) = use_mmap ? IOBuffer(Mmap.mmap(filename)) : Parsers.BufferedIO(open(filename))
getio(io::IO, use_mmap) = Parsers.BufferedIO(io)
getname(str::String) = str
getname(filename) = String(filename)
getname(io::I) where {I <: IO} = string("<", I, ">")

function consumeBOM!(io)
Expand Down Expand Up @@ -269,7 +269,7 @@ function __init__()
end

"""
`CSV.read(fullpath::Union{AbstractString,IO}, sink=DataFrame; kwargs...)` => `typeof(sink)`
`CSV.read(fullpath, sink=DataFrame; kwargs...)` => `typeof(sink)`

Parses a delimited file into a Julia structure (a DataFrame by default, but any valid Tables.jl sink function can be provided).

Expand Down Expand Up @@ -309,7 +309,7 @@ Supported keyword arguments include:
"""
function read end

function read(fullpath::Union{AbstractString,IO}, sink=DataFrame, args...; append::Bool=false, transforms::AbstractDict=Dict{Int,Function}(), kwargs...)
function read(fullpath, sink=DataFrame, args...; append::Bool=false, transforms::AbstractDict=Dict{Int,Function}(), kwargs...)
if !isempty(args)
Base.depwarn("`CSV.read(source, $sink, $args)` is deprecated; pass a valid Tables.jl sink function as the 2nd argument directly", nothing)
sink = sink(args...)
Expand Down