Skip to content

Commit 1656650

Browse files
use LazyModules.jl
1 parent 62105e0 commit 1656650

File tree

13 files changed

+168
-90
lines changed

13 files changed

+168
-90
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
1616
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
1717
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
1818
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
19+
LazyModules = "8cdb02fc-e678-4876-92c5-9defec4f444e"
1920
MAT = "23992714-dd62-5051-b70f-ba57cb901cac"
2021
MLUtils = "f1d291b0-491e-4a28-83b9-f70985020b54"
2122
NPZ = "15e1cf62-19b3-5cfa-8e77-841668bca605"
@@ -37,6 +38,7 @@ HDF5 = "0.16.2"
3738
ImageCore = "0.9"
3839
JLD2 = "0.4.21"
3940
JSON3 = "1"
41+
LazyModules = "0.3"
4042
MAT = "0.10"
4143
MLUtils = "0.2.0"
4244
NPZ = "0.4.1"

docs/src/containers/overview.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ MLDatasets.jl contains several reusable data containers for accessing datasets i
55
```@docs
66
FileDataset
77
TableDataset
8-
HDF5Dataset
9-
Base.close(::HDF5Dataset)
10-
JLD2Dataset
11-
Base.close(::JLD2Dataset)
128
CachedDataset
139
MLDatasets.make_cache
1410
```
11+
12+
<!--
13+
# TODO add back to docs when included again in the pkg
14+
HDF5Dataset
15+
Base.close(::HDF5Dataset)
16+
JLD2Dataset
17+
Base.close(::JLD2Dataset)
18+
-->
19+

src/MLDatasets.jl

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,40 @@ module MLDatasets
33
using FixedPointNumbers
44
using SparseArrays
55
using Tables
6-
# using Glob
7-
# using DataFrames
8-
# import ImageCore
96
using DataDeps
107
import MLUtils
118
using MLUtils: getobs, numobs, AbstractDataContainer
129
using ColorTypes
13-
14-
### I/O imports
15-
# import NPZ
16-
# import Pickle
17-
# using MAT: matopen, matread
18-
using FileIO
19-
# import CSV
20-
# using HDF5
21-
# using JLD2
22-
# import JSON3
10+
using Glob
2311
using DelimitedFiles: readdlm
24-
##########
12+
using FileIO
13+
using LazyModules: @lazy
14+
15+
include("require.jl") # export @require
16+
17+
# Use `@lazy import SomePkg` whenever the returned types are not its own types,
18+
# since for methods applied on the returned types we would encounter in world-age issues
19+
# (see discussion in https://github.com/JuliaML/MLDatasets.jl/pull/128).
20+
# In the other case instead, use `require import SomePkg` to force
21+
# the use to manually import.
22+
23+
@require import JSON3="0f8b85d8-7281-11e9-16c2-39a750bddbf1"
24+
@require import DataFrames="a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
25+
@lazy import ImageCore="a09fc81d-aa75-5fe9-8630-4744c3626534"
26+
# @lazy import NPZ # lazy imported by FileIO
27+
@lazy import Pickle="fbb45041-c46e-462f-888f-7c521cafbc2c"
28+
@lazy import MAT="23992714-dd62-5051-b70f-ba57cb901cac"
29+
@lazy import CSV="336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
30+
@lazy import HDF5="f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
31+
# @lazy import JLD2
2532

2633
export getobs, numobs # From MLUtils.jl
2734

2835
include("abstract_datasets.jl")
2936
# export AbstractDataset,
3037
# SupervisedDataset
3138

32-
include("imports.jl")
39+
# include("imports.jl")
3340
include("utils.jl")
3441
export convert2image
3542

@@ -39,16 +46,16 @@ include("io.jl")
3946
include("download.jl")
4047

4148
### API to be revisited with conditional module loading
42-
# include("containers/filedataset.jl")
43-
# export FileDataset
44-
# include("containers/tabledataset.jl")
45-
# export TableDataset
49+
include("containers/filedataset.jl")
50+
export FileDataset
51+
include("containers/tabledataset.jl")
52+
export TableDataset
4653
# include("containers/hdf5dataset.jl")
4754
# export HDF5Dataset
4855
# # include("containers/jld2dataset.jl")
4956
# # export JLD2Dataset
50-
# include("containers/cacheddataset.jl")
51-
# export CachedDataset
57+
include("containers/cacheddataset.jl")
58+
export CachedDataset
5259

5360
# Misc.
5461
include("datasets/misc/boston_housing.jl")

src/containers/tabledataset.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ function Base.length(dataset::TableDataset)
5050
end
5151

5252
# fast access for DataFrame
53-
Base.getindex(dataset::TableDataset{<:DataFrame}, i) = dataset.table[i, :]
54-
Base.length(dataset::TableDataset{<:DataFrame}) = nrow(dataset.table)
53+
# Base.getindex(dataset::TableDataset{<:DataFrame}, i) = dataset.table[i, :]
54+
# Base.length(dataset::TableDataset{<:DataFrame}) = nrow(dataset.table)
5555

5656
# fast access for CSV.File
5757
# Base.getindex(dataset::TableDataset{<:CSV.File}, i) = dataset.table[i]

src/datasets/misc/boston_housing.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ function BostonHousing(; as_df = true, dir = nothing)
7878
@assert dir === nothing "custom `dir` is not supported at the moment."
7979
path = joinpath(@__DIR__, "..", "..", "..", "data", "boston_housing.csv")
8080
df = read_csv(path)
81-
DFs = require_import(:DataFrames)
82-
features = df[!, DFs.Not(:MEDV)]
81+
features = df[!, DataFrames.Not(:MEDV)]
8382
targets = df[!, [:MEDV]]
8483

8584
metadata = Dict{String, Any}()

src/datasets/misc/iris.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,9 @@ end
8080
function Iris(; dir = nothing, as_df = true)
8181
path = datafile("Iris", "iris.data", dir)
8282
df = read_csv(path, header=0)
83-
DFs = require_import(:DataFrames)
84-
DFs.rename!(df, ["sepallength", "sepalwidth", "petallength", "petalwidth", "class"])
83+
DataFrames.rename!(df, ["sepallength", "sepalwidth", "petallength", "petalwidth", "class"])
8584

86-
features = df[!, DFs.Not(:class)]
85+
features = df[!, DataFrames.Not(:class)]
8786
targets = df[!, [:class]]
8887

8988
metadata = Dict{String, Any}()

src/datasets/misc/titanic.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ function Titanic(; as_df = true, dir = nothing)
6262
@assert dir === nothing "custom `dir` is not supported at the moment."
6363
path = joinpath(@__DIR__, "..", "..", "..", "data", "titanic.csv")
6464
df = read_csv(path)
65-
DFs = require_import(:DataFrames)
66-
67-
features = df[!, DFs.Not(:Survived)]
65+
66+
features = df[!, DataFrames.Not(:Survived)]
6867
targets = df[!, [:Survived]]
6968

7069
metadata = Dict{String, Any}()

src/datasets/vision/cifar10.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ convert2image(::Type{<:CIFAR10}, x::AbstractArray{<:Integer}) =
165165
function convert2image(::Type{<:CIFAR10}, x::AbstractArray{T,N}) where {T,N}
166166
@assert N == 3 || N == 4
167167
x = permutedims(x, (3, 2, 1, 4:N...))
168-
ImageCore = lazy_import(:ImageCore)
169168
return ImageCore.colorview(RGB, x)
170169
end
171170

src/datasets/vision/mnist.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ convert2image(::Type{<:MNIST}, x::AbstractArray{<:Integer}) =
141141
function convert2image(::Type{<:MNIST}, x::AbstractArray{T,N}) where {T,N}
142142
@assert N == 2 || N == 3
143143
x = permutedims(x, (2, 1, 3:N...))
144-
ImageCore = lazy_import(:ImageCore)
145144
return ImageCore.colorview(Gray, x)
146145
end
147146

src/imports.jl

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)