Skip to content

Commit

Permalink
[#10] - Generalizando entrada do TablesConnector
Browse files Browse the repository at this point in the history
  • Loading branch information
Conradox committed Aug 19, 2020
1 parent 63e4fd3 commit 13e037c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/connector.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Tables, StatsBase
using Tables, Random

abstract type AbstractConnector{T} end

Expand All @@ -21,14 +21,14 @@ Base.length(conn::TablesConnector) = length(conn.rows)

hasnext(conn::TablesConnector) = conn.state < length(conn)

function TablesConnector(df::DataFrames.DataFrame;
function TablesConnector(df::T;
orderBy = nothing,
rev = false,
shuffle = false)
shuffle = false) where {T}

shuffle == true ? df = df[StatsBase.shuffle(1:size(df,1)), :] : orderBy != nothing && sort!(df, DataFrames.order(orderBy, rev=rev))
shuffle == true ? df = df[Random.shuffle(1:size(df,1)), :] : orderBy != nothing && sort!(df, orderBy, rev = rev)

return TablesConnector{DataFrame}(Tables.rows(df), 0)
return TablesConnector{T}(Tables.rows(df), 0)
end

TablesConnector(filename::String) = TablesConnector{DataFrame}(CSV.read(filename; header = false))

0 comments on commit 13e037c

Please sign in to comment.