Skip to content

Improve docstring for calculate_mean_and_stdv() #57

@ehrenfeu

Description

@ehrenfeu

The docstring should explain in which situations the function will return 0, 0 as a result, i.e. which inputs for values_list will lead to this.

Originally posted by @ehrenfeu in #49 (comment)

def calculate_mean_and_stdv(values_list, round_decimals=0):
"""Calculate mean and standard deviation from a list of floats.
Parameters
----------
values_list : list of int,float
List containing numbers.
round_decimals : int, optional
Rounding decimal to use for the result, by default 0
Returns
-------
tuple of (float, float)
Mean and standard deviation of the input list.
"""
filtered_list = [x for x in values_list if x is not None]
if not filtered_list:
return 0, 0
mean = round(sum(filtered_list) / len(filtered_list), round_decimals)
variance = sum((x - mean) ** 2 for x in filtered_list) / len(filtered_list)
std_dev = round(variance ** 0.5, round_decimals)
return mean, std_dev

Metadata

Metadata

Assignees

Labels

documentationMissing documentation, docstring conventions, ...

Type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions