joshuaulrich / xts

Extensible time series class that provides uniform handling of many R time series classes by extending zoo.
http://joshuaulrich.github.io/xts/
GNU General Public License v2.0
220 stars 71 forks source link

index of xts object changes from class Date to POSIXct when applying (in-/)equality operations #336

Closed timsalmutter closed 4 years ago

timsalmutter commented 4 years ago

Description

When one applies an equality or inequality operation to an xts object with index class date, the result is an xts object where the index class is now POSIXct. The problem does NOT occur for other operations like +, -, *, /, etc. The problem seems to arise in the xts:::Ops.xts function.

Expected behavior

Expected behavior should be that the index class does not change by this operation.

Minimal, reproducible example

require(xts)
data("sample_matrix")
xtsSample <- as.xts(sample_matrix)
index(xtsSample) <- as.Date(index(xtsSample))
class(index(xtsSample > 0))

Session Info

R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=German_Austria.1252  LC_CTYPE=German_Austria.1252    LC_MONETARY=German_Austria.1252
[4] LC_NUMERIC=C                    LC_TIME=German_Austria.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] xts_0.12-0 zoo_1.8-7 

loaded via a namespace (and not attached):
[1] compiler_3.6.1  tools_3.6.1     grid_3.6.1      lattice_0.20-38
joshuaulrich commented 4 years ago

Thanks for the report. This is a duplicate of #322, which has been fixed but not released...

I guess this is a good indication that I should make a release. ;-)