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

Closes #1678; dimnames.data.table properly uses inherits to check data.frame awareness #1679

Merged
merged 1 commit into from
Apr 27, 2016

Conversation

MichaelChirico
Copy link
Member

Wasn't sure how to add proper tests, since we need to invoke !cedta() to get the original error.

@codecov-io
Copy link

codecov-io commented Apr 27, 2016

Current coverage is 90.68%

Merging #1679 into master will decrease coverage by -0.00%

@@             master      #1679   diff @@
==========================================
  Files            55         55          
  Lines         10144      10149     +5   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits           9202       9203     +1   
- Misses          942        946     +4   
  Partials          0          0          
  1. File src/forder.c (not in diff) was modified. more
    • Misses +4
    • Partials 0
    • Hits -4

Sunburst

Powered by Codecov. Last updated by d10868a

@@ -2022,7 +2022,12 @@ as.list.data.table <- function(x, ...) {

dimnames.data.table <- function(x) {
if (!cedta()) {
if (!identical(class(x),c("data.table","data.frame"))) stop("data.table inherits from data.frame (from v1.5) but this data.table does not. Has it been created manually (e.g. by using 'structure' rather than 'data.table') or saved to disk using a prior version of data.table? The correct class is c('data.table','data.frame').")
if (!inherits(x, "data.frame"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be if (!is.data.table(x)). Also could you please leave the error message as is.. no need for unnecessary paste.

Copy link
Member Author

@MichaelChirico MichaelChirico Apr 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arunsrinivasan I think the fact that it gets here in the first place (unless a user invokes data.table:::dimnames.data.table directly -- and anyone doing that better know what they're doing) implies that inherits(x, "data.table") is TRUE, since something dispatched to a data.table method. Am I mistaken?

This is why I think we can ditch the test altogether -- seems this worry about x being data.table but not data.frame is pretty obsolete.

If we do test, we should test for data.frame so we're sure dimnames.data.frame is proper to dispatch.

Copy link
Member

@arunsrinivasan arunsrinivasan Apr 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see what you mean. Sounds good. Could you please make that as the only change? Thanks.

It's meant to handle cases where one does:

x = list(1:2, 3:4)
setattr(x, 'class', "data.table")

Rare, but a possibility.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arunsrinivasan you mean to remove the test, or to keep inherits(x, "data.frame") but remove the paste?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latter.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

…a.frame awareness

honing bug fix update

un-paste
@arunsrinivasan arunsrinivasan merged commit e9f1d1d into Rdatatable:master Apr 27, 2016
@MichaelChirico MichaelChirico deleted the dimnames branch April 27, 2016 23:12
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

Successfully merging this pull request may close these issues.

3 participants