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

Metrics allow negative numbers #65

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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