Skip to content

Check numeric equality before using format - #136

Merged
hadley merged 1 commit into
mainfrom
numeric-format
Mar 12, 2022
Merged

hadley merged 1 commit into
mainfrom
numeric-format

Conversation

@hadley

@hadley hadley commented Mar 11, 2022

Copy link
Copy Markdown
Member

Fixes #134

test_that("don't use format if numeric & within tolerance", {
dt <- as.POSIXct("2016-07-18 16:06:00", tz = "UTC")
expect_snapshot({
compare(dt, dt + 5)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

that means timestamps 5 seconds apart are considered equal? seems strange to me

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

compare() never errors; see the snapshot for the actual results.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

in what sense are dt and dt+5 within 1e-8 of each other?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The tolerance is relative, not absolute.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

(This behaviour isn't new; it's just exposed by the change to use format. I'll tackle it in a separate issue.)

@hadley
hadley merged commit 0d344ae into main Mar 12, 2022
@hadley
hadley deleted the numeric-format branch March 12, 2022 17:37
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.

Don't use format if ignore_attr = TRUE

2 participants