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

accessing rows via a factor column throws error #1361

Closed
mplatzer opened this issue Sep 25, 2015 · 5 comments
Closed

accessing rows via a factor column throws error #1361

mplatzer opened this issue Sep 25, 2015 · 5 comments
Assignees
Labels
Milestone

Comments

@mplatzer
Copy link

this used to work in data.table v1.9.4 but now throws an error in v1.9.6:

dt <- data.table(i=1:10, f=as.factor(1:10))
dt[f==3]

the thrown error is: Error in bmerge(i, x, leftcols, rightcols, io <- FALSE, xo, roll = 0, : x.'f' is a factor column being joined to i.'V1' which is type 'double'. Factor columns must join to factor or character columns.

the error can be avoided by adding additional conditions, e.g. dt[f==3 & TRUE] or by comparing to characters (as indicated by the error itself): dt[f=="3"]. not sure, whether this is a bug or a feature, but I though it's worthwhile reporting.

@ghost
Copy link

ghost commented Sep 25, 2015

Just found something similar. I had working code with the previous CRAN release, so something must have been changed in 1.9.6.

set.seed(1)
DT <- data.table(V1=factor(c(1,2)),
                 V2=LETTERS[1:3],
                 V4=1:12)


# does not work
DT[V1 == 1, ]

# does work
DT[V1 == factor(1), ]

While in 1.9.4:

DT[V1 == factor(1), ]
Error in Ops.factor(V1, factor(1)) : level sets of factors are different

@caneff
Copy link

caneff commented Sep 28, 2015

Running into this too. This seems to be very similar to isssue #957 but with factors instead of characters.

@caneff
Copy link

caneff commented Sep 28, 2015

The problem seems to be that on line 471 of data.table.R, you check

mode(x[[isub2]]) != mode(RHS)

However, both factors and integers have mode "numeric", so it skips this part and moves on to the standard auto-indexing, where bmerge chokes. I'm not sure what the right substitution is for line 471 but that is where the fix should go.

@caneff
Copy link

caneff commented Oct 1, 2015

Ping? This is breaking our existing code so we are stuck with 1.9.4 until this gets fixed.

@arunsrinivasan arunsrinivasan added this to the v1.9.8 milestone Oct 6, 2015
@arunsrinivasan arunsrinivasan self-assigned this Oct 11, 2015
@ghost
Copy link

ghost commented Oct 23, 2015

Here http://stackoverflow.com/questions/32934400/gather-multiple-times-at-once someone mentions in the comments that this problem can be circumvented by turning off auto indexing in v1.9.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants