JuliaData / JuliaData/DataFramesMeta.jl

@replace for in-place conditional updating

Open
#144 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
496
Forks
56
PR merge metrics
No merged PRs in 30d

Description

From Slack, I was looking for a good way to replicate something like

inds = (alldata.year .<= 1993) .& (alldata.ishead .== true)
alldata.labor_inc_spouse[inds] .= alldata.labor_inc_pre_spouse[inds]

in one line. In Stata this would be replace labor_inc_spouse = labor_inc_pre_spouse if year <= 1993 & ishead == true

@bkamins suggested

alldata.labor_inc_spouse .= ifelse.((alldata.year .<= 1993) .& (alldata.ishead .== true), alldata.labor_inc_pre_spouse, alldata.labor_inc_spouse)

which operates in place and is efficient.

It could be nice to have a macro version of that like

@replace(df, :labor_inc_spouse = :labor_inc_pre_spouse if :year .<= 1993 & :ishead .== true)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue does not name any files, tests, or entry points. Start by reviewing existing DataFramesMeta macro APIs and the proposed @replace syntax, then determine the intended semantics for conditional in-place updates. Done should mean the macro supports the shown assignment and condition while preserving values outside the condition.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.