zalando / expan

Open-source Python library for statistical analysis of randomised control trials (A/B tests)
MIT License
335 stars 50 forks source link

Default Parameters of Constructor of Experiment class #151

Closed michaelcyng closed 7 years ago

michaelcyng commented 7 years ago

In the class expan.core.experiment.Experiment, the constructor starts with the following:

def init(self, control_variant_name, data, metadata, report_kpi_names=[], derived_kpis=[]):

It is not a good idea to have mutable values (i.e. empty list) as the default parameter value because Python does not create a new empty list for you every time you create an object. Instead, it creates it only once and then, it will reference to the same list every time so the next time you create an Experiment object, it is possible that a non-empty list is passed to the function.

I suggest to replace the square brackets by "None". And then, inside the function if report_kpi_names is None: report_kpi_names = list()

In that case, it can guarantee an empty list for the function.

Details of this problem can be found: http://docs.python-guide.org/en/latest/writing/gotchas/

shansfolder commented 7 years ago

Thank you @michaelcyng. That's a good point. Will address it soon.

shansfolder commented 7 years ago

done in #152