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

Add support for Tables.jl #87

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
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
ShowCases = "605ecd9f-84a6-4c9e-81e2-4798472b76a3"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

[compat]
ChainRulesCore = "1.0"
Expand Down
1 change: 1 addition & 0 deletions src/MLUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ChainRulesCore: rrule
using ChainRulesCore: @non_differentiable, unthunk, AbstractZero,
NoTangent, ZeroTangent, ProjectTo

using Tables: istable, rows

include("observation.jl")
export numobs,
Expand Down
8 changes: 4 additions & 4 deletions src/observation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ See also [`getobs`](@ref)
function numobs end

# Generic Fallbacks
numobs(data) = length(data)
numobs(data) = istable(data) ? length(rows(data)) : length(data)

"""
getobs(data, [idx])
Expand All @@ -40,13 +40,13 @@ Every author behind some custom data container can make this
decision themselves.
The output should be consistent when `idx` is a scalar vs vector.

See also [`getobs!`](@ref) and [`numobs`](@ref)
See also [`getobs!`](@ref) and [`numobs`](@ref)
"""
function getobs end

# Generic Fallbacks
getobs(data) = data
getobs(data, idx) = data[idx]
getobs(data, idx) = istable(data) ? collect(rows(data))[idx] : data[idx]
Copy link
Member

Choose a reason for hiding this comment

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

Collecting all rows is too expensive, let's wait for the outcome of the discussion here
JuliaData/Tables.jl#278 (comment)


"""
getobs!(buffer, data, idx)
Expand Down Expand Up @@ -82,7 +82,7 @@ Base.lastindex(x::AbstractDataContainer) = numobs(x)
# --------------------------------------------------------------------
# Arrays
# We are very opinionated with arrays: the observation dimension
# is th last dimension. For different behavior wrap the array in
# is th last dimension. For different behavior wrap the array in
# a custom type, e.g. with Tables.table.


Expand Down