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

Merging zero-width objects removes the index #379

Closed
joshuaulrich opened this issue Oct 24, 2022 · 1 comment
Closed

Merging zero-width objects removes the index #379

joshuaulrich opened this issue Oct 24, 2022 · 1 comment

Comments

@joshuaulrich
Copy link
Owner

merge.xts() needs to handle this the same as merge.zoo(). We also need to handle the cases where join is "left" or "right".

# zoo handles this correctly
#
z1 <- structure(numeric(0),
  index = structure(1:10, class = "Date"), class = "zoo")
z2 <- structure(numeric(0),
  index = structure(5:14, class = "Date"), class = "zoo")

merge(z1, z2)  # all index values
## Data:
## numeric(0)
## 
## Index:
##  [1] "1970-01-02" "1970-01-03" "1970-01-04" "1970-01-05" "1970-01-06" "1970-01-07" "1970-01-08"
##  [8] "1970-01-09" "1970-01-10" "1970-01-11" "1970-01-12" "1970-01-13" "1970-01-14" "1970-01-15"

merge(z1, z2, all = FALSE)  # only values in both objects
## Data:
## numeric(0)
## 
## Index:
## [1] "1970-01-06" "1970-01-07" "1970-01-08" "1970-01-09" "1970-01-10" "1970-01-11"

# xts, however...
merge(as.xts(z1), as.xts(z2))
## Data:
## numeric(0)
## 
## Index:
## POSIXct of length 0

merge(as.xts(z1), as.xts(z2), all = FALSE)
## Data:
## numeric(0)
## 
## Index:
## POSIXct of length 0


### Session Info
sessionInfo()                                                                                   
## R version 4.2.1 (2022-06-23)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 20.04.5 LTS
## 
## Matrix products: default
## BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
##  [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
## [10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats     graphics  grDevices datasets  utils     methods   base     
## 
## other attached packages:
## [1] xts_0.12.2.1 zoo_1.8-11  
## 
## loaded via a namespace (and not attached):
## [1] compiler_4.2.1  bspm_0.3.10     grid_4.2.1      lattice_0.20-45
@joshuaulrich
Copy link
Owner Author

Whoops, this is a duplicate of #227.

joshuaulrich added a commit that referenced this issue Oct 31, 2022
merge.xts() would return empty xts objects if called on two or more
zero-width xts objects. merge.zoo() would return a zero-width object
with the correct index.

Also needed to update tests for subsetting zero-width objects to check
behavior versus zoo instead of comparing with hard-coding xts objects.

Fixes #227. See #379.
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

1 participant