Conversation
Codecov Report
@@ Coverage Diff @@
## master #2150 +/- ##
==========================================
+ Coverage 90.75% 90.78% +0.03%
==========================================
Files 59 59
Lines 11584 11585 +1
==========================================
+ Hits 10513 10518 +5
+ Misses 1071 1067 -4
Continue to review full report at Codecov.
|
mattdowle
left a comment
There was a problem hiding this comment.
Great spot and thanks for the pull. Comments inline.
| dups = FALSE # fix for #1513 | ||
| # using rep.int instead of rep speeds things up considerably (but attributes are dropped). | ||
| j = lapply(l, class) # changed "vapply" to avoid errors with "ordered" "factor" input | ||
| tzones = lapply(l, function(col) attr(col, 'tzone')) |
There was a problem hiding this comment.
This can be tzones = lapply(l, attr, 'tzone') please and can it be moved down inside the if() so that it is only calculated when needed?
There was a problem hiding this comment.
Makes sense. Was trying to mirror the code that copies over classes. Any reason the j = ... line above my edit isn't inside the else if?
| l[[i]] = rep.int(rep.int(y, times = rep.int(x[i], n[i])), times = nrow/(x[i]*n[i])) | ||
| if (any(class(l[[i]]) != j[[i]])) | ||
| setattr(l[[i]], 'class', j[[i]]) # reset "Date" class - rep.int coerces to integer | ||
| if (any(!sapply(tzones, is.null))) { |
There was a problem hiding this comment.
Are the tzone for all columns being looked at here, within a loop through columns? It doesn't seem quite right to me but I haven't debugged or run it. See next comment on tests.
There was a problem hiding this comment.
I think that this if-statement can be simply removed.
It serves no real purpose. If the tzones are all NULL, well, let them all be NULL and set them anyways.
There was a problem hiding this comment.
I suppose this could make sense if is.null is significantly faster than just setting the attributes even if they're NULL? In any case, the same would go for the lines that reset class immediately above?
There was a problem hiding this comment.
The difference to the line about the class is, that the latter tests for each i.
So, if we want to retain the tzone if-statement, it should read:
if(!is.null(tzones[[i]])){...}. That would make more sense in my opinion.
|
|
||
| # CJ should retain timezone information, #2029 | ||
| df <- CJ(week=as.POSIXct('2016-01-01', tz = 'UTC'), id=1:10) | ||
| test(1762, attr(df$week, 'tzone'), 'UTC') |
There was a problem hiding this comment.
More tests please including multi-column data.table with 1 and 2 columns of POSIXct with other non-POSIXct (say plain integer) columns at the beginning, middle and end. Enough variations to test that the code is actually retaining the tzone on the desired columns and not adding tzones to columns that shouldn't, because I'm not sure it's right currently just by glancing at it. The test is just a single column.
There was a problem hiding this comment.
You mean something likeCJ(dt1=as.POSIXct('2016-01-01', tz = 'UTC'), id=1:10, dt2=as.POSIXct(c('2016-01-01', '2016-01-02'), tz = 'UTC')) (behaves as expected) and various permutations of the order of these columns?
|
Dear RoyalTS, thanks a lot for taking care of this. One suggestion / proposal: I would be happy to contribute, if you like. Kind regards, Markus |
|
I have below posted a CJ implementation that consistently retains all attributes and addresses Matt's concerns . Additionally, I have proposed a comprehensive set of tests of the new implementation that also addresses Matt's comments. I conducted a benchmark for a ten-column CJ (2 rows in each column) input to test if the
| Both implementations are just as fast as the master. Therefore, I would propose to keep the There is, however, a speed issue when all ten columns have an attribute that needs to be replaced:
Again, there is no difference between the implementation with Kind regards, Here is the code: And here are the tests |
|
This is great! How should we do this? Close this PR and you'll create one of your own? |
|
I am not familiar with github. Can't you give me push rights for your PR? Or you just insert the suggestions yourself, and tell in the news that I also contributed. |
due to MarkusBonsch
|
Just made the changes, all tests are passing. Can we get another reviewer pass on this? |
|
Do you know, why this AppVeyor check fails? It leaves this nasty red cross at the project. |
|
Just more recent patches creating merge conflicts. All resolved, this is now mergeable again in principle. |
fixes #2029