Skip to content

Commit 288c3a8

Browse files
committed
also add a friendly error for mismatch
1 parent c85f497 commit 288c3a8

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/data/dataloader.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,10 @@ _nobs(data::AbstractArray) = size(data)[end]
109109
function _nobs(data::Union{Tuple, NamedTuple})
110110
length(data) > 0 || throw(ArgumentError("Need at least one data input"))
111111
n = _nobs(data[1])
112-
if !all(x -> _nobs(x) == n, Base.tail(data))
113-
throw(DimensionMismatch("All data should contain same number of observations"))
112+
for i in keys(data)
113+
ni = _nobs(data[i])
114+
n == ni || throw(DimensionMismatch("All data inputs should have the same number of observations, i.e. size in the last dimension. " *
115+
"But data[$(repr(first(keys(data))))] ($(summary(data[1]))) has $n, while data[$(repr(i))] ($(summary(data[i]))) has $ni."))
114116
end
115117
return n
116118
end

0 commit comments

Comments
 (0)