Skip to content

Commit ba3a9fc

Browse files
committed
update docstring + passing function to mode in update/!
1 parent 0561066 commit ba3a9fc

File tree

5 files changed

+55
-477
lines changed

5 files changed

+55
-477
lines changed

docs/src/man/joins.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ julia> innerjoin(store, roster, on = [:store => :store, :date => (:start_date, :
408408

409409
## Update a data set by values from another data set
410410

411-
`update!` updates a data set values by using values from a transaction data set. The function uses the given keys (`on = ...`) to select rows for updating. By default, the missing values in transaction data set wouldn't replace the values in the main data set, however, using `allowmissing = true` changes this behaviour. If there are multiple rows in the main data set which match the key(s), using `mode = :all` causes all of them to be updated, and `mode = :missing` causes only the ones which are missing in the main data set to be updated. If there are multiple rows in the transaction data set which match the key, only the last one will be used to update the main data set.
411+
`update!` updates a data set values by using values from a transaction data set. The function uses the given keys (`on = ...`) to select rows for updating. By default, the missing values in transaction data set wouldn't replace the values in the main data set, however, using `allowmissing = true` changes this behaviour. If there are multiple rows in the main data set which match the key(s), using `mode = :all` causes all of them to be updated, `mode = :missing` causes only the ones which are missing in the main data set to be updated, and `mode = fun` updates the values which calling `fun` on them returns `true`. If there are multiple rows in the transaction data set which match the key, only the last one (given `stable = true` is passed) will be used to update the main data set.
412412

413413
The `update!` functions replace the main data set with the updated version, however, if a copy of the updated data set is required, the `update` function can be used instead.
414414

@@ -474,4 +474,19 @@ julia> update(main, transaction, on = [:group, :id],
474474
5 │ G2 1 1.3 3
475475
6 │ G2 1 2.1 3
476476
7 │ G2 2 0.0 2
477+
478+
julia> update(main, transaction, on = [:group, :id],
479+
mode = isequal(2.3))
480+
7×4 Dataset
481+
Row │ group id x1 x2
482+
│ identity identity identity identity
483+
│ String? Int64? Float64? Int64?
484+
─────┼─────────────────────────────────────────
485+
1 │ G1 1 1.2 5
486+
2 │ G1 1 2.3 4
487+
3 │ G1 2 missing 4
488+
4 │ G1 2 2.5 2
489+
5 │ G2 1 1.3 1
490+
6 │ G2 1 2.1 missing
491+
7 │ G2 2 0.0 2
477492
```

src/join/join_dict.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,21 @@ function _update!_dict(dsl, dsr, ranges, onleft, onright, right_cols, ::Val{T};
403403

404404
_fill_ranges_for_dict_join!(ranges, dict, maxprob, _fl, _fr, _columns(dsl)[onleft[1]], _columns(dsr)[onright[1]], sz, type)
405405

406+
if mode == :all
407+
f_mode = x->true
408+
elseif mode == :missing || mode == :missings
409+
f_mode = x->ismissing(x)
410+
else
411+
f_mode = x->mode(x)::Bool
412+
end
413+
406414
for j in 1:length(right_cols)
407415
if haskey(index(dsl).lookup, _names(dsr)[right_cols[j]])
408416
left_cols_idx = index(dsl)[_names(dsr)[right_cols[j]]]
409417
TL = nonmissingtype(eltype(_columns(dsl)[left_cols_idx]))
410418
TR = nonmissingtype(eltype(_columns(dsr)[right_cols[j]]))
411419
if promote_type(TR, TL) <: TL
412-
_update_left_with_right!(_columns(dsl)[left_cols_idx], _columns(dsr)[right_cols[j]], ranges, allowmissing, mode)
420+
_update_left_with_right!(_columns(dsl)[left_cols_idx], _columns(dsr)[right_cols[j]], ranges, allowmissing, f_mode)
413421
end
414422
end
415423
end

0 commit comments

Comments
 (0)