-
Notifications
You must be signed in to change notification settings - Fork 1k
updated bmerge() to support joins on complex columns with zero imaginary part, treating them as double
#7085
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
Open
venom1204
wants to merge
4
commits into
master
Choose a base branch
from
issue6627
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -231,6 +231,12 @@ A \code{data.table} is a \code{list} of vectors, just like a \code{data.frame}. | |
|
|
||
| See the \code{see also} section for the several other \emph{methods} that are available for operating on data.tables efficiently. | ||
|
|
||
|
|
||
| A \code{data.table} supports joins on columns of type \code{complex}. The join logic is as follows: | ||
| \itemize{ | ||
| \item If a \code{complex} column contains values with only a zero imaginary part (e.g., \code{10+0i}), it is treated as a \code{double} for the join, allowing it to match with \code{integer} and \code{double} columns successfully. | ||
| \item If any value in a \code{complex} join column has a non-zero imaginary part (e.g., \code{10+2i}), the join will stop with an error, as there is no defined way to sort or match such a number against a real number. | ||
| } | ||
| } | ||
| \references{ | ||
| \url{https://r-datatable.com} (\code{data.table} homepage)\cr | ||
|
|
@@ -441,6 +447,27 @@ DT[, c(.(y=max(y)), lapply(.SD, min)), by=rleid(v), .SDcols=v:b] | |
| # Support guide and links: | ||
| # https://github.com/Rdatatable/data.table/wiki/Support | ||
|
|
||
| # Example: Joining with a system that uses complex IDs (#6627) | ||
|
|
||
| # Case 1: Joining a "clean" set of products. | ||
| # Here, `products_clean` only contains IDs with zero imaginary parts. | ||
| products_clean = data.table(id = c(101+0i, 103+0i), name = c("widget", "thingamajig")) | ||
| sales = data.table(product_id = c(101, 103), units_sold = c(50, 75)) | ||
|
|
||
| # This join works because the 'id' column in `products_clean` has no non-zero imaginary parts. | ||
| products_clean[sales, on = .(id = product_id), nomatch = 0] | ||
|
|
||
| # Case 2: Joining a list that includes "bad" IDs. | ||
| # Here, `products_all` contains an ID with a non-zero imaginary part (102+1i). | ||
| products_all = data.table(id = c(101+0i, 102+1i, 103+0i), name = c("widget", "gadget", "thingamajig")) | ||
|
|
||
| # The join fails because the entire 'id' column is checked first. | ||
| try(products_all[sales, on = .(id = product_id), nomatch = 0]) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please remove. |
||
|
|
||
| \dontshow{ | ||
| rm(products_clean, sales, products_all) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't have any rm() commands in dontshow in other Rd files, please remove. |
||
| } | ||
|
|
||
| \dontrun{ | ||
| if (interactive()) { | ||
| vignette(package="data.table") # 9 vignettes | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this feature is desirable. For the new example using current master I get
which seems totally reasonable and actionable. If I want a join, I would need to convert the types to be the same.
So I would suggest closing this pr and opening a new one that clarifies the documentation. What do you think @jangorecki @MichaelChirico @ben-schwen @aitap ?
(I don't really use complex numbers so I don't understand if this is a typical or desirable use case, but I guess any user is capable of converting complex to another joinable type)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I would not add examples of joining of complex columns into the manual. It is just too uncommon. Unit tests yes, NEWS entry yes, but manual examples not really.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thank you for the detailed feedback.
I understand there are two key takeaways from the discussion:
Please let me know the final decision on the feature design and how you'd like me to proceed. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please ask @MichaelChirico for review because he filed the original issue.