Skip to content

Commit

Permalink
Metrics allow negative numbers (#65)
Browse files Browse the repository at this point in the history
* metrics allow negative numbers

* metrics allow negative numbers
  • Loading branch information
jancervenka authored Nov 21, 2023
1 parent 05392d0 commit 6219bb5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/epstats/toolkit/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
ParseException,
alphanums,
delimitedList,
Optional,
)
import pandas as pd

Expand All @@ -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("< = > <= >= =^ !=")
Expand Down Expand Up @@ -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}"
Expand Down
17 changes: 16 additions & 1 deletion tests/epstats/toolkit/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6219bb5

Please sign in to comment.