-
Notifications
You must be signed in to change notification settings - Fork 54
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
#285
base: main
Are you sure you want to change the base?
Add nrow
and ncol
#285
Conversation
The DataAPI.jl defines |
That would be great yes. Then
How can I make |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I see that what I wanted is a minimal type piracy, but I think it is OK.
You do not need to do anything more than you did. Tables.jl does not export anything, but |
Codecov Report
@@ Coverage Diff @@
## main #285 +/- ##
==========================================
- Coverage 94.88% 94.32% -0.56%
==========================================
Files 7 7
Lines 665 670 +5
==========================================
+ Hits 631 632 +1
- Misses 34 38 +4
Continue to review full report at Codecov.
|
src/fallbacks.jl
Outdated
# get the number of rows in the incoming table | ||
function rowcount(cols) | ||
"Return the number of rows in the incoming table." | ||
function nrow(cols) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bkamins, does this not pirate a default definition? I'm a little uncomfortable with this definition because technically rowcount
was only meant to be called on the result of Tables.columns
, but now it "looks like" it works generically on any table. And for the most part, it probably will, but we're not really following the principles of the interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this not pirate a default definition?
DataAPI.jl does not define any method for this function. Same for ncol
- DataAPI.jl does not define any method for this function.
As I have commented - it does pirate as it add the definition to ncol
with ::Any
signature. The problem is exactly what you have commented - some tables might not have a well defined row count (maybe also the same problem is for ncol
). So what do you think would be best to do? What I would ideally have is some definition that works by default correctly. I think that if default errors it is not a huge problem if it does not error on "standard" tables.
Maybe what we should do is:
- leave
rowcount
to be internal; - define
nrow
andncol
only for tables defined in Tables.jl tables (rowtable
,coltable
,dictrowtable
,dictcolumntable
,table
maybe some more? - you know best)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's what I would prefer (only define for Tables.jl-defined tables. I'm also happy to add recommendations to the docs that table types should strongly consider implementing nrow
/ncol
on their own table types as apart of the API.
src/fallbacks.jl
Outdated
@deprecate rowcount(x) nrow(x) | ||
|
||
"Return the number of columns in the incoming table." | ||
ncol(cols) = length(columnnames(cols)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here; columnnames
and getcolumn
are only technically allowed to be called on the result of Tables.columns
or on individual iterated rows from Tables.rows
, so this makes me a bit uncomfortable.
Co-authored-by: Jacob Quinn <[email protected]>
@quinnj will know best if you correctly covered everything :), but for matrices things look good :). |
I noticed that there is a
rowcount
, but not acolumncount
and thatlength(columnnames(cols))
was used in the codebase to count the number of columns (because that is the fastest?). This PR suggests to add acolumncount
function.