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

Remove DataFrames dependency #19

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ version = "0.1.0"
CodecXz = "ba30903b-d9e8-5048-a5ec-d1f5b0d4b47b"
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"
CodecZstd = "6b39b394-51ab-5f42-8807-6242bab2b4c2"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
TranscodingStreams = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"
Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

[extras]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
test = ["DataFrames", "Test"]
1 change: 0 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ julia 1.1
CodecXz
CodecZlib
CodecZstd
DataFrames
TranscodingStreams
23 changes: 19 additions & 4 deletions src/TableReader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ using Dates:
@dateformat_str
using Unicode:
isletter
using DataFrames:
DataFrame
using TranscodingStreams:
TranscodingStreams,
TranscodingStream,
Expand Down Expand Up @@ -316,6 +314,23 @@ function checkformat(stream::IO)
end
end

function new_name!(used, name)
n, i = name, 1
while n in used
n = Symbol("$(name)_$i")
i += 1
end
push!(used, n)
return n
end

function to_uniquetuple(names)
used = Set{Symbol}()
return Tuple(new_name!(used, name) for name in names)
end

to_namedtuple(cols, names) = NamedTuple{to_uniquetuple(names)}(cols)

# The main function of parsing a character delimited file.
# `stream` is asuumed to be an input stream of plain text.
function readdlm_internal(stream::TranscodingStream, params::ParserParameters)
Expand Down Expand Up @@ -375,7 +390,7 @@ function readdlm_internal(stream::TranscodingStream, params::ParserParameters)
_, i = scanline!(tokens, 1, mem, 0, lastnl, line, params)
if i == 1 && location(tokens[1,1])[2] == 0
# no data
return DataFrame([[] for _ in 1:length(colnames)], colnames, makeunique = true)
return to_namedtuple([[] for _ in 1:length(colnames)], colnames)
elseif i == ncols
# the header and the first row have the same number of columns
elseif i == ncols + 1
Expand Down Expand Up @@ -490,7 +505,7 @@ function readdlm_internal(stream::TranscodingStream, params::ParserParameters)
end
end

return DataFrame(columns, colnames, makeunique = true)
return to_namedtuple(columns, colnames)
end

# Count the number of `byte` in a memory block.
Expand Down
1 change: 1 addition & 0 deletions test/REQUIRE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DataFrames
Loading