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 nrow and ncol #124

Closed
xiaodaigh opened this issue Nov 26, 2019 · 10 comments
Closed

add nrow and ncol #124

xiaodaigh opened this issue Nov 26, 2019 · 10 comments

Comments

@xiaodaigh
Copy link

No description provided.

@joshday
Copy link
Contributor

joshday commented Nov 26, 2019

I don't see a benefit to having this in Tables at the cost of adding more methods to the interface.

@pdeffebach
Copy link

Is the canonical recommendation to do this nrow = length(Tables.rows(t)) and ncol = length(Tables.columns(t))? if t = Tables.columns(df)?

@xiaodaigh
Copy link
Author

length(Tables.rows(t))

Works because many iterators has the has length traits

@joshday
Copy link
Contributor

joshday commented Nov 26, 2019

To expand, "most" tables in practice have a length, but the Tables interface doesn't guarantee it. This is what I would do to get nrows and ncols from column/row iterators:

t = Tables.columns(df)

nrows = length(first(t))

ncols = length(t) 
t2 = Tables.rows(df)

nrows = length(t2)

ncols = length(first(t2))

@pdeffebach
Copy link

Thanks for the note.

Just to be clear, the iteration itself is determined by DataFrames (for example), so length may not be guaranteed either.

I was under the impression iteration was implemented by Tables.jl via some sort of

getproperty(t, s) for s in propertynames(t)

@pdeffebach
Copy link

Also your second example doesn't work for generic tables because iteration on rows isn't defined, even as a fallback. Ref #75

@joshday
Copy link
Contributor

joshday commented Nov 26, 2019

Just to be clear, the iteration itself is determined by DataFrames (for example), so length may not be guaranteed either.

Correct. A DataFrame probably has length defined, but other things may not. Tables doesn't need the length method in order to function, but most things probably have a length.

iteration on rows isn't defined

Iteration over a single row isn't guaranteed, but rows(t) returns an iterator. In both my examples, there's no guarantee that any of those length methods exist, but in practice they probably do.

@xiaodaigh
Copy link
Author

https://docs.julialang.org/en/v1/manual/interfaces/

There is an IteratorSize() type checker and the default is HasLength() trait. Mostly, likely rows would return an iterator that has length

@ablaom
Copy link
Contributor

ablaom commented Nov 28, 2019

You can get the number of columns from length(Tables.schema(X).names):

julia> using Tables

julia> X = (x1=rand(3), x2=rand(3)) 
(x1 = [0.893945, 0.696079, 0.544089],
 x2 = [0.162807, 0.0328988, 0.567906],)

julia> length(Tables.schema(X).names)
2

@quinnj
Copy link
Member

quinnj commented Feb 8, 2020

I think there have been enough clarifications and suggestions here; but yeah, I dont' think we need anything in the interface for this.

@quinnj quinnj closed this as completed Feb 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants