Skip to content

Commit daef202

Browse files
fix crossreference
1 parent 62afef3 commit daef202

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

docs/src/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Pkg.add("MLDatasets")
2525

2626
Datasets are grouped into different categories. Click on the links below for a full list of datasets available in each category.
2727

28-
- [Graphs Datasets](@ref) - datasets with an underlying graph structure: Cora, PubMed, CiteSeer, ...
28+
- [Graph Datasets](@ref) - datasets with an underlying graph structure: Cora, PubMed, CiteSeer, ...
2929
- [Miscellaneuous Datasets](@ref) - datasets that do not fall into any of the other categories: Iris, BostonHousing, ...
3030
- [Text Datasets](@ref) - datasets for language models.
3131
- [Vision Datasets](@ref) - vision related datasets such as MNIST, CIFAR10, CIFAR100, ...

src/MLDatasets.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ include("datasets/vision/cifar10.jl")
8484
export CIFAR10
8585
include("datasets/vision/cifar100_reader/CIFAR100Reader.jl")
8686
include("datasets/vision/cifar100.jl")
87-
export CIFAR100#
87+
export CIFAR100
8888
include("datasets/vision/svhn2.jl")
8989
export SVHN2
9090

9191
## Text
92-
#
92+
9393
include("datasets/text/ptblm.jl")
9494
export PTBLM
9595
include("datasets/text/udenglish.jl")

src/containers/tabledataset.jl

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ struct TableDataset{T} <: AbstractDataContainer
1212
# TableDatasets must implement the Tables.jl interface
1313
function TableDataset{T}(table::T) where {T}
1414
Tables.istable(table) ||
15-
throw(ArgumentError("TableDatasets must implement the Tabels.jl interface"))
15+
throw(ArgumentError("The input must implement the Tables.jl interface"))
1616

1717
new{T}(table)
1818
end
1919
end
2020

2121
TableDataset(table::T) where {T} = TableDataset{T}(table)
22-
# TableDataset(path::AbstractString) = TableDataset(DataFrame(CSV.File(path)))
22+
TableDataset(path::AbstractString) = TableDataset(read_csv(path))
2323

2424
# slow accesses based on Tables.jl
2525
_getobs_row(x, i) = first(Iterators.peel(Iterators.drop(x, i - 1)))
@@ -29,26 +29,32 @@ function _getobs_column(x, i)
2929

3030
return NamedTuple{colnames}(rowvals)
3131
end
32-
function Base.getindex(dataset::TableDataset, i)
33-
if Tables.rowaccess(dataset.table)
34-
return _getobs_row(Tables.rows(dataset.table), i)
35-
elseif Tables.columnaccess(dataset.table)
36-
return _getobs_column(dataset.table, i)
32+
33+
function getobs_table(table, i)
34+
if Tables.rowaccess(table)
35+
return _getobs_row(Tables.rows(table), i)
36+
elseif Tables.columnaccess(table)
37+
return _getobs_column(table, i)
3738
else
3839
error("The Tables.jl implementation used should have either rowaccess or columnaccess.")
3940
end
4041
end
41-
function Base.length(dataset::TableDataset)
42-
if Tables.columnaccess(dataset.table)
43-
return length(Tables.getcolumn(dataset.table, 1))
44-
elseif Tables.rowaccess(dataset.table)
42+
43+
function numobs_table(table)
44+
if Tables.columnaccess(table)
45+
return length(Tables.getcolumn(table, 1))
46+
elseif Tables.rowaccess(table)
4547
# length might not be defined, but has to be for this to work.
46-
return length(Tables.rows(dataset.table))
48+
return length(Tables.rows(table))
4749
else
4850
error("The Tables.jl implementation used should have either rowaccess or columnaccess.")
4951
end
5052
end
5153

54+
Base.getindex(dataset::TableDataset, i) = getobs_table(dataset.table, i)
55+
Base.length(dataset::TableDataset) = numobs_table(dataset.table)
56+
57+
5258
# fast access for DataFrame
5359
# Base.getindex(dataset::TableDataset{<:DataFrame}, i) = dataset.table[i, :]
5460
# Base.length(dataset::TableDataset{<:DataFrame}) = nrow(dataset.table)
@@ -60,6 +66,7 @@ end
6066
## Tables.jl interface
6167

6268
Tables.istable(::TableDataset) = true
69+
6370
for fn in (:rowaccess, :rows, :columnaccess, :columns, :schema, :materializer)
6471
@eval Tables.$fn(dataset::TableDataset) = Tables.$fn(dataset.table)
6572
end

0 commit comments

Comments
 (0)