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

shift no longer works on matrix type under 1.14.3 #5287

Closed
ethanbsmith opened this issue Dec 12, 2021 · 5 comments · Fixed by #5462
Closed

shift no longer works on matrix type under 1.14.3 #5287

ethanbsmith opened this issue Dec 12, 2021 · 5 comments · Fixed by #5462
Assignees
Milestone

Comments

@ethanbsmith
Copy link
Contributor

shift used to work on matrix columns, but now generates and error. i dont see anything in the NEWS. is this intentional as its a breaking change?

works in 1.14.0

sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252 LC_NUMERIC=C                           LC_TIME=English_United States.1252    

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

loaded via a namespace (and not attached):
[1] compiler_4.1.2    tools_4.1.2       data.table_1.14.0 checkpoint_1.0.0 
> data.table::shift(matrix(1:10, ncol = 1))
 [1] NA  1  2  3  4  5  6  7  8  9

not working under 1.14.3

 sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252 LC_NUMERIC=C                           LC_TIME=English_United States.1252    

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

loaded via a namespace (and not attached):
[1] compiler_4.1.2    tools_4.1.2       data.table_1.14.3 checkpoint_1.0.0 
> data.table::shift(matrix(1:10, ncol = 1))
Error in data.table::shift(matrix(1:10, ncol = 1)) : 
  'as' must not be matrix or array
@ethanbsmith ethanbsmith changed the title 1.14.3 shift no longer works on matrix type shift no longer works on matrix type under 1.14.3 Dec 12, 2021
@ben-schwen
Copy link
Member

Introduced in #5189. It's erroring because coerceAs cannot handle matrix/arrays.
Same error ofc also appears for nafill(matrix(c(NA, 1:9), ncol = 1), fill=0) which also happened to "work" before #4491.

According to docs shift/nafill never supported matrix but happened to work because matrices/array are R internally represented via one-dimensonial arrays with attributes.

@jangorecki are there reasons why coerceAs(x, as, copy) doesn't allow matrices/arrays for arguments x and as?

@jangorecki
Copy link
Member

jangorecki commented Dec 13, 2021

There reason is that there was no such requirement when it was implemented.
https://rdatatable.gitlab.io/data.table/library/data.table/html/shift.html does not mention matrix, but "A vector, list, data.frame or data.table" only, as Ben pointed out.

@MichaelChirico
Copy link
Member

the fix in this case is very simple:

data.table::shift(c(matrix(1:10, ncol = 1)))

The earlier behavior on multi-column matrices is IMO quite undesirable, so I'm happy to break it in this case. Though we could improve the error message by catching it earlier.

@ethanbsmith
Copy link
Contributor Author

ethanbsmith commented Dec 19, 2021 via email

@mattdowle mattdowle added this to the 1.14.3 milestone Aug 18, 2022
@jangorecki
Copy link
Member

Though we could improve the error message by catching it earlier.

Was about to do it, but realized I will just copy error message from coerceAs into nafill and shift. IMO it's better to catch it there, in single a place.

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

Successfully merging a pull request may close this issue.

5 participants