Skip to content
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

Allow variable neutralization in YAML test files #1021

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

benjello
Copy link
Member

@benjello benjello commented May 18, 2021

Connected to openfisca/openfisca-france#1481

New features

  • Allow variable neutralization in YAML test files`

@benjello benjello requested review from sandcha and bonjourmauko May 18, 2021 14:09
CHANGELOG.md Outdated Show resolved Hide resolved
@sandcha
Copy link
Collaborator

sandcha commented May 20, 2021

@benjello Do you have an example where you needed to neutralize a variable in a YAML test?

Is it useful to temporarily check a behavior? I imagine that we can use the YAML tests with this new option to check the effect of a reform. Or is it useful for another use case?

@benjello
Copy link
Member Author

It is useful when you will use a specific "reform" of the tax benefit system consisting only of neutralizing some variables for example to avoid never ending spirals for example to focus on some specific domains. Our use case right now is France's assurance-chômage.

@benjello
Copy link
Member Author

@sandcha @maukoquiroga : can I merge this PR ?

Copy link
Collaborator

@sandcha sandcha left a comment

Choose a reason for hiding this comment

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

Thank you @benjello for this new feature!
Here is a commit with a test example that fails. Could you fix it or update the way of testing the feature? 🤔

CHANGELOG.md Outdated Show resolved Hide resolved
@sandcha
Copy link
Collaborator

sandcha commented Jun 1, 2021

It is useful when you will use a specific "reform" of the tax benefit system consisting only of neutralizing some variables for example to avoid never ending spirals for example to focus on some specific domains. Our use case right now is France's assurance-chômage.

@benjello Is it also true to say that to check the French unemployment insurance (that, in its last reform, neutralizes some old incomes when a person becomes unemployed), it's useful to define YAML tests with the neutralized incomes to check the unemployment insurance formula?

@benjello benjello changed the title Alloz variable neutralization in YAML test files Allow variable neutralization in YAML test files Jun 1, 2021
@benjello
Copy link
Member Author

benjello commented Jun 1, 2021

@sandcha : I was more concerned by neutralizing many resources that may induce spirals that needs a lot of initialisation to be circumvent.

@benjello
Copy link
Member Author

benjello commented Jun 1, 2021

And I do not understand why the test is not passing since it passes locally on my computer ...

@sandcha
Copy link
Collaborator

sandcha commented Jun 2, 2021

@benjello in case we have a difference on the command, here is what I used:

pytest tests/core/test_yaml.py

And this is what the CI does as well.

@benjello
Copy link
Member Author

benjello commented Jun 2, 2021

@sandcha : I used

openfisca test tests/core/yaml_tests/test_with_neutralized_variables.yaml 

and it pass.

But if i try exactly what you did I do have a failure.

Which is strange BTW.

@sandcha
Copy link
Collaborator

sandcha commented Jun 7, 2021

The error at pytest tests/core/test_yaml.py execution might be linked to the tax_benefit_system as it is shared between yaml tests when it's identified as the same tbs. So here are two commits to set a specific tbs to the cache when there are neutralized variables.

The test_yaml.py now only works when test_with_extension and test_name_filter are commented. When they are not, the thrown errors seem to be linked to the next test in the test_yaml.py file. 🙃 🤔

@sandcha
Copy link
Collaborator

sandcha commented Jun 8, 2021

When we run pytest tests/core/test_yaml.py, the Holder of a neutralized variable (like basic_income in the YAML test) doesn't remember that the variable is neutralized (while he does when the same test in executed with openfisca test tests/core/yaml_tests/test_with_neutralized_variables.yaml).
We can see that by printing what happens in the get_array function of openfisca_core/holders/holder.py file.

Then, when we look further:

  • openfisca test tests/core/yaml_tests/test_with_neutralized_variables.yaml runs openfisca_core/taxbenefitsystems/tax_benefit_system.py file get_variable and load_variable methods before running the tests and get_variable within test execution.
  • pytest tests/core/test_yaml.py doesn't call get_variable or load_variable before the tests and even if it runs get_variable during test execution, it doesn't come with the variable.is_neutralized attribute.

@benjello
Copy link
Member Author

@sandcha : can I help you on this or are you still exploring ?

@sandcha
Copy link
Collaborator

sandcha commented Jun 17, 2021

@benjello Yes, of course it would be great if you looked into the holders difference between the pytest and the openfisca test command! That's why I shared the last debugging results above :)
We can also decide to cut the issue into two subjects: open an issue on the holders for python tests and merge this PR if we are confident about the openfisca test behavior.

@benjello
Copy link
Member Author

I am not sure I can help you a lot with the pytest machinery I never used ... Can't we, actually shoudn't we, align both ?

@MattiSG @maukoquiroga we need you here !

@benjello
Copy link
Member Author

benjello commented Jul 6, 2021

@cbenz : could you help us here ?

@MattiSG
Copy link
Member

MattiSG commented Aug 9, 2021

Can't we, actually shoudn't we, align both?

Yes, this is a major issue if both are expected to be used interchangeably. However, I only see references to openfisca test in the doc, and personally only use that one, which makes sense to me as some OpenFisca-specific test machinery / setup is used.

@sandcha under which circumstances do you use pytest? Do you have a specific reason for preferring it over openfisca test?

Copy link
Member

@MattiSG MattiSG left a comment

Choose a reason for hiding this comment

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

I don't have a strong opinion on the code, it seems of consistent quality and readability with the existing codebase.

I fail to understand two points:

  1. In which way is this different from forcing the value of a variable to some value in the tested situation?
  2. Can you please confirm this only makes available in YAML declarative tests a feature that already exists in the Python API (neutralize_variable)?

In any case, this behaviour should be documented (both Python and YAML).

@bonjourmauko bonjourmauko added the kind:feat A feature request, a feature deprecation label Aug 11, 2021
@benjello
Copy link
Member Author

Thanks @MattiSG for your questions:

    1. Neutralizing sets a variable to its default value for every period so using it in YAML matches the Python API
    1. Yes.

I will open a companion doc if it is ok with you.

@benjello
Copy link
Member Author

It is actually documented on the pyhton API but the doc is broken as noted here.

@MattiSG
Copy link
Member

MattiSG commented Aug 24, 2021

Thank you for these replies @benjello!

Unblocking this PR

I understand that:

I honestly start wondering if we should not get rid of the Makefile altogether and move the instructions in openfisca commands and in act if #1030 is confirmed.

Syntax discussion

It is probably a good thing to enable further YAML / Python equivalence.
However, I am not super excited about the current proposed syntax:

- name: "Result outside neutralized variables"
   period: 2021-01
   neutralized_variables:
     - housing_allowance
   input:
     age: 30
   output:
     basic_income: 600

Is “neutralising” the variable an economic domain term? If not, I would be more in favour of being more explicit and using something like force_default:

- name: "Result outside neutralized variables"
   period: 2021-01
   input:
     age: 30
   output:
     basic_income: 600
   force_default:
     - housing_allowance

Alternatively, what about using a special default keyword in YAML? This would make the syntax as follows:

- name: "Result outside neutralized variables"
   period: 2021-01
   input:
     age: 30
   output:
     basic_income: 600
     housing_allowance: default

@benjello
Copy link
Member Author

@MattiSG : I am not opposed to a change in terminology.
But I would use the force_default keyword since the variable is set to default for every period.
The other notation is more prone to interpretation and we definitively want to avoid that.

@MattiSG
Copy link
Member

MattiSG commented Aug 24, 2021

the variable is set to default for every period

Ah, that's an important point to note indeed! Then, there is a bit of an issue with the current syntax, as force_default (or neutralized_variables) is at the same level as period. It doesn't seem clear to me that the default value will be enforced for all periods 🤔

What about never_calculate?

@benjello
Copy link
Member Author

What about never_calculate?

Then I would prefer neutralize ;-) but I won't die on that hill.

period could be changed to default period but it would be longer and not add much since you know that you will test for at least one specific period when you write your tests.

@bonjourmauko
Copy link
Member

Can't we, actually shoudn't we, align both?

Yes, this is a major issue if both are expected to be used interchangeably. However, I only see references to openfisca test in the doc, and personally only use that one, which makes sense to me as some OpenFisca-specific test machinery / setup is used.

@sandcha under which circumstances do you use pytest? Do you have a specific reason for preferring it over openfisca test?

I think the use of pytest being misleading, that's why in #1020 I propose to use just openfisca test instead.

@benjello benjello force-pushed the neutralize-variable-in-test branch from 27c7cfc to 201db36 Compare August 31, 2021 11:40
benjello added a commit to openfisca/openfisca-doc that referenced this pull request Aug 31, 2021
@benjello
Copy link
Member Author

So if I understand correctly #1020 will fix the test right @maukoquiroga ?

So we will wait for #1020 to get this one in then openfisca/openfisca-doc#252.

cc @MattiSG @HAEKADI @sandcha

@bonjourmauko
Copy link
Member

So if I understand correctly #1020 will fix the test right @maukoquiroga ?

So we will wait for #1020 to get this one in then openfisca/openfisca-doc#252.

cc @MattiSG @HAEKADI @sandcha

Most probably, and if there's some more work to do it is lost in the middle of #1031.

By the way, yaml tests in core are not meant to be run "as-is" they're there to test the Yaml Test API (some of them are expected to fail).

@benjello benjello force-pushed the neutralize-variable-in-test branch from 201db36 to b9984f2 Compare September 9, 2021 14:47
@benjello
Copy link
Member Author

benjello commented Sep 9, 2021

@maukoquiroga : I rebased after the recent fix of the doc but there are still problems with this PR I do not understand.
Could you give me a hint ?

@bonjourmauko
Copy link
Member

@benjello I think it is because you have to rebase also the corresponding branch in the doc.

@benjello
Copy link
Member Author

benjello commented Sep 9, 2021

@maukoquiroga : I do not understand what I am supposed to do to have the tests passing. Do you mean that I have to merge the doc branch first ?

@benjello
Copy link
Member Author

@maukoquiroga @MattiSG @sandcha : could you give me a hint of what I should fix to have this PR and its companion openfisca/openfisca-doc#252.

Thanks !

Fix text for comparison with country-template parameter

Bump

Update CHANGELOG.md

Co-authored-by: sandcha <sandcha@users.noreply.github.com>

Test neutralized_variables new attribute for YAML tests

Update CHANGELOG.md

Co-authored-by: sandcha <sandcha@users.noreply.github.com>

Add tbs with neutralized variables to yaml tbs cache

fixup! Add tbs with neutralized variables to yaml tbs cache

Add test on yaml runner on tbs cache with neutralized variable

fixup! Add test on yaml runner on tbs cache with neutralized variable
@benjello benjello force-pushed the neutralize-variable-in-test branch from 1b8642e to e07cac4 Compare November 22, 2022 09:08
@benjello
Copy link
Member Author

@maukoquiroga : I rebased this branch and there is a broken test and I cannot understand why !
Could you give it a look ? Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:feat A feature request, a feature deprecation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants