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

Comparing xts objects with 'Date' indices gives warnings #258

Closed
baoyunfan opened this issue Jul 24, 2018 · 3 comments
Closed

Comparing xts objects with 'Date' indices gives warnings #258

baoyunfan opened this issue Jul 24, 2018 · 3 comments

Comments

@baoyunfan
Copy link

baoyunfan commented Jul 24, 2018

Description

Comparing xts objects with 'Date' indices gives warnings. The resultant xts object's index seems to be changed to 'POSIXct'.

Expected behavior

Warning message:
timezone of object (UTC) is different than current timezone ().

Minimal, reproducible example

library(xts)
a <- xts(1:5, order.by = Sys.Date()+1:5)
b <- xts(5:1, order.by = Sys.Date()+1:5)
res <- a < b
print(res)
print(zoo::index(a))
print(zoo::index(res))

Session Info

R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] xts_0.11-0 zoo_1.8-3 

loaded via a namespace (and not attached):
[1] compiler_3.5.0  tools_3.5.0     yaml_2.1.19     grid_3.5.0      lattice_0.20-35
@braverock
Copy link
Contributor

Your warning (not an error) is because all Date indices have timezone 'UTC', as has been true and documented for a while. Your local timezone is different.

Also, you've created a false comparison.

xts objects are always ordered by time. You can't create an xts object with a decreasing index.

@baoyunfan
Copy link
Author

baoyunfan commented Jul 24, 2018 via email

@joshuaulrich
Copy link
Owner

This is a duplicate of #249. Tom Andrews' comment illustrates why this happens:

library(xts)
test <- .xts(1:5, 1:5, tclass = "Date")
attr(test > 2, "tclass")
# [1] "POSIXct" "POSIXt"

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

No branches or pull requests

3 participants