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

all.equal.data.table gets ignore.indices argument #6136

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mb706
Copy link

@mb706 mb706 commented May 15, 2024

Indices can now be ignored in all.equal() when ignore.indices is set:

x <- data.table(a = 1)
y <- data.table(a = 1)
x[a == 1]
#>        a
#>    <num>
#> 1:     1
all.equal(x, y)
#> [1] "Datasets have different indices. 'target': [a]. 'current': has no index."
all.equal(x, y, ignore.indices = TRUE)
#> [1] TRUE

closes #6134

@@ -104,8 +104,8 @@ fsetequal = function(x, y, all=TRUE) {

# all.equal ----

all.equal.data.table = function(target, current, trim.levels=TRUE, check.attributes=TRUE, ignore.col.order=FALSE, ignore.row.order=FALSE, tolerance=sqrt(.Machine$double.eps), ...) {
stopifnot(is.logical(trim.levels), is.logical(check.attributes), is.logical(ignore.col.order), is.logical(ignore.row.order), is.numeric(tolerance), is.data.table(target))
all.equal.data.table = function(target, current, trim.levels=TRUE, check.attributes=TRUE, ignore.indices=FALSE, ignore.col.order=FALSE, ignore.row.order=FALSE, tolerance=sqrt(.Machine$double.eps), ...) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why we are adding a new argument in the middle? This might break downstream code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to group ignore.indices with check.attributes as they seem most related, as indices are attributes. I would say that users should always pass all.equal's optional arguments by name, since these are usually passed on recursively, which makes positional argument passing risky with all.equal beyond the first two. If you want me to, I can move ignore.indices to the end.

@ben-schwen
Copy link
Member

What about keys?

@mb706
Copy link
Author

mb706 commented May 16, 2024

From my view the case for ignoring keys is less strong, since they do not appear automatically (I believe?) and also change the behaviour of the data.table object in more relevant ways. Ultimately that would be your decision, I can also implement ignoring keys (with an ignore.key argument) if you want me to.

@ben-schwen
Copy link
Member

Nah, keys are more intrusive since they also change the layout of how the data is stored, so I share your opinion that they are substantial and it might be less common to ignore them.

What just crossed my mind is instead of adding a new argument we could extend check.attributes to also accept character vectors to specify attributes that should be ignored. This seems more versatile.

@mb706
Copy link
Author

mb706 commented May 16, 2024

check.attributes to also accept character vectors to specify attributes that should be ignored.

It would be nicer if it were called ignore.attributes. IDK how you handle these cases, you could introduce an argument ignore.attributes with default !check.attributes and deprecate check.attributes?

In any case, the index attribute would still get special treatment. In this PR the line

   if (!ignore.indices) {

would need to be changed to

   if (!"index" %in% ignore.attributes) {

@mb706
Copy link
Author

mb706 commented May 27, 2024

Any opinions on which route you want to go with this? Should check.attributes be a vector of attribute names to be ignored? Should it be renamed ignore.attributes or something? or should I leave ignore.indices (and if so, should I move it to the end of the argument list)?

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 this pull request may close these issues.

Optionally ignore indices in all.equal
2 participants