From 6219bb5bd911bc8db807855aa60f988f7c483168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C4=8Cervenka?= Date: Tue, 21 Nov 2023 19:47:41 +0100 Subject: [PATCH] Metrics allow negative numbers (#65) * metrics allow negative numbers * metrics allow negative numbers --- setup.cfg | 2 +- src/epstats/toolkit/parser.py | 5 +++-- tests/epstats/toolkit/test_parser.py | 17 ++++++++++++++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/setup.cfg b/setup.cfg index e9f9670..727b478 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = ep-stats -version = 2.2.4 +version = 2.2.5 description = Statistical package to evaluate ab tests in experimentation platform. long_description = file: README.md long_description_content_type = text/markdown diff --git a/src/epstats/toolkit/parser.py b/src/epstats/toolkit/parser.py index 6614903..c8814aa 100644 --- a/src/epstats/toolkit/parser.py +++ b/src/epstats/toolkit/parser.py @@ -10,6 +10,7 @@ ParseException, alphanums, delimitedList, + Optional, ) import pandas as pd @@ -25,7 +26,7 @@ def __init__(self, nominator: str, denominator: str): unit_type = Word(alphas + "_").setParseAction(UnitType) agg_type = Word(alphas).setParseAction(AggType) goal = Word(alphas + "_" + nums).setParseAction(Goal) - number = Word(nums).setParseAction(Number) + number = (Optional("-") + Word(nums)).setParseAction(Number) dimension = Word(alphanums + "_").setParseAction(Dimension) dimension_value_chars = alphanums + "_" + "-" + "." + "%" + " " + "/" + "|" dimension_operator = oneOf("< = > <= >= =^ !=") @@ -199,7 +200,7 @@ def __str__(self): class Number: def __init__(self, t): - self.value = float(t[0]) + self.value = float("".join(t)) def __str__(self): return f"{self.value}" diff --git a/tests/epstats/toolkit/test_parser.py b/tests/epstats/toolkit/test_parser.py index 51f5e64..33b2862 100644 --- a/tests/epstats/toolkit/test_parser.py +++ b/tests/epstats/toolkit/test_parser.py @@ -4,7 +4,7 @@ import pytest from pyparsing import ParseException -from src.epstats.toolkit.parser import Parser +from src.epstats.toolkit.parser import Parser, MultBinOp def test_evaluate_agg(): @@ -347,6 +347,21 @@ def test_operator_position_not_correct(dimension_value): ) +@pytest.mark.parametrize( + "nominator", + [ + "2 * count(test_unit_type.global.conversion)", + "-1 * count(test_unit_type.global.conversion)", + ], +) +def test_numbers(nominator): + + assert isinstance( + Parser(nominator, "count(test_unit_type.unit.conversion)")._nominator_expr, + MultBinOp, + ) + + def assert_count_value(evaluation, count, value, value_sqr, precision=5): assert_almost_equal(evaluation[0], count, precision) assert_almost_equal(evaluation[1], value, precision)