From e0ebd8ed3b5cc3aabbbfaf1c45b794da04e9f8da Mon Sep 17 00:00:00 2001 From: ZJ Dai Date: Sun, 6 Oct 2024 14:02:14 +1100 Subject: [PATCH] fix: loading rows for JDFFiles --- Project.toml | 2 +- build-readme.jl | 2 +- src/JDFFile.jl | 20 +++++++++----------- src/Tables.jl | 9 +++++++++ 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/Project.toml b/Project.toml index 6872b1f..3b6ebb0 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "JDF" uuid = "babc3d20-cd49-4f60-a736-a8f9c08892d3" authors = ["Dai ZJ "] -version = "0.5.2" +version = "0.5.3" [deps] Blosc = "a74b3585-a348-5f62-a45c-50e91977d574" diff --git a/build-readme.jl b/build-readme.jl index e13d622..fa8975b 100644 --- a/build-readme.jl +++ b/build-readme.jl @@ -7,7 +7,7 @@ upcheck() using Weave -weave("../README.jmd", out_path="c:/git/JDF/", doctype="github") +weave("../README.jmd", out_path="./", doctype="github") if false # debug diff --git a/src/JDFFile.jl b/src/JDFFile.jl index ffc7900..19020c8 100644 --- a/src/JDFFile.jl +++ b/src/JDFFile.jl @@ -71,17 +71,15 @@ function Base.getindex(file::JDFFile, col::Symbol) JDF.load(file; cols = [col])[col] end +function Base.getindex(file::JDFFile, rows, col::String) + # TODO make it load from column loader for faster access + getfield(JDF.load(file; cols = [col]), Symbol(col))[rows, :] +end +function Base.getindex(file::JDFFile, rows, cols::AbstractVector{String}) + JDF.load(file; cols = cols)[rows, :] +end -# function Base.getindex(file::JDFFile, rows, col::String) -# # TODO make it load from column loader for faster access -# getfield(JDF.load(file; cols = [col]), Symbol(col))[rows] -# end - -# function Base.getindex(file::JDFFile, rows, cols::AbstractVector{String}) -# JDF.load(file; cols = cols)[rows, :] -# end - -# Base.view(file::JDFFile, rows, cols) = getindex(file, rows, cols) +Base.view(file::JDFFile, rows, cols) = getindex(file, rows, cols) -# getindex(file::JDFFile, rows, cols) = JDF.load(file)[rows, cols] +getindex(file::JDFFile, rows, cols) = JDF.load(file)[rows, cols] diff --git a/src/Tables.jl b/src/Tables.jl index 9cc4af3..47822be 100644 --- a/src/Tables.jl +++ b/src/Tables.jl @@ -41,3 +41,12 @@ Tables.istable(t::Table) = true function Base.getindex(t::Table, col::Symbol) t.columns[col] end + +function Base.getindex(t::Table, rows, col::Symbol) + t.columns[col][rows] +end + +function Base.getindex(t::Table, rows, ::Colon) + # TODO probably not efficient + NamedTuple{names(t.columns)}([nt[rows] for nt in t.columns]) +end