openfisca-core icon indicating copy to clipboard operation
openfisca-core copied to clipboard

Allow creation of Variable Aliases

Open benjello opened this issue 6 years ago • 3 comments

Hi there!

I really enjoy OpenFisca, but I recently encountered an issue.

What I need

I would like to create an alias for a variable of a tax-benefit-system. Imagine that I want to compare different countries system, say England and France. I need a common framework. Imagine that I have similar variables called disposable_income in the first country and revenu_disponible in the other one. I may choose to a use a common name by sticking to english. So I would like to enrich my France tax-benefit-system with a new "phony" variable called disposable_income which acts exactly as revenu_disponible.

Is that easily feasible ?

Context

I identify more as a:

  • Analyst (I make macroscopic computations on real populations).
  • Developer (I create tools that use the existing OpenFisca code).

cc @sandcha @Morendil @maukoquiroga @fpagnoux

benjello avatar Jan 16 '19 11:01 benjello

That would be a really nice feature, and of great help for research purposes!

Perhaps "alias" is not the best word for it, to me that implies something internal to one model; what you describe is more a "mapping" between two models, and to make it work smoothly there is perhaps more work to be done, e.g. being able to load two TaxBenefitSystem instances simultaneously and running the same simulation on each.

The question is, how would we make it work with the current implementation of Variables, which are reified as classes? I've been thinking about this lately and I see the rationale (classes can easily hold the Python code for formulas), what I also see is the many downsides. You can't have more than one class of the same name, and aliases would be more difficult to implement than they should be.

I would support (and contribute to) an effort to redesign the way Variables are implemented. I'm not super optimistic about doing this with Variables as they currently exist, and the same considerations apply for #807.

Morendil avatar Jan 16 '19 14:01 Morendil

I think we should be able to intercept calls to get_variable and equivalent methods to take into account an alias. This would also help making country packages breaking change less frequent where a variable is renamed.

I've been thinking about this lately and I see the rationale (classes can easily hold the Python code for formulas)

Yep, this was the only way to unify the declaration of a function and some attributes in the same place in Python 😞

fpagnoux avatar Feb 06 '19 13:02 fpagnoux

See also #750.

Morendil avatar May 13 '19 10:05 Morendil

@benjello I agree with @Morendil in that this is actually a neat feature but very hard to implement today.

I'm closing this issue due to lack of activity, yet please do not hesitate to reopen it if someone has an idea or proposal for implementing the requested solution.

bonjourmauko avatar Dec 06 '22 21:12 bonjourmauko