Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Countess-project/countess
Browse files Browse the repository at this point in the history
  • Loading branch information
nickzoic committed Aug 29, 2024
2 parents adee2d2 + bf58ca0 commit 3ef5c5f
Show file tree
Hide file tree
Showing 16 changed files with 831 additions and 233 deletions.
156 changes: 34 additions & 122 deletions .github/workflows/run-tests-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,148 +11,60 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: "3.9"
cache: 'pip'
- run: sudo apt install xvfb
- run: pip install --upgrade pip
- run: pip install .[dev]
- run: xvfb-run pytest tests/
- run: xvfb-run pytest -v -rP --doctest-modules countess/ tests/

run-tests-ubuntu-22_04-python-3_10-with-coverage:
run-tests-ubuntu-22_04-python-3_10:
runs-on: ubuntu-22.04
name: Ubuntu 22.04, Python 3.10 (with coverage)
name: Ubuntu 22.04, Python 3.10
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: 'pip'
- run: sudo apt install xvfb
- run: pip install --upgrade pip
- run: pip install .[dev]
- run: xvfb-run coverage run --source countess -m pytest tests/
# - run: coverage html
# - uses: actions/upload-artifact@v3
# with:
# name: test coverage report
# path: htmlcov/*
- run: echo '### Coverage Report' >> $GITHUB_STEP_SUMMARY
- run: coverage report --format=markdown --skip-empty --sort=-cover >> $GITHUB_STEP_SUMMARY

# run-tests-ubuntu-22_04-python-3_11_0rc2:
# runs-on: ubuntu-22.04
# name: Ubuntu 22.04, Python 3.11.0rc2
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-python@v4
# with:
# python-version: "3.11.0-rc.2"
# - run: sudo apt install xvfb
# - run: pip install --upgrade pip
# - run: pip install .[dev]
# - run: xvfb-run pytest tests/
#
# run-tests-ubuntu-22_04-python-3_11_0:
# runs-on: ubuntu-22.04
# name: Ubuntu 22.04, Python 3.11.1
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-python@v4
# with:
# python-version: "3.11.0"
# - run: sudo apt install xvfb
# - run: pip install --upgrade pip
# - run: pip install .[dev]
# - run: xvfb-run pytest tests/
#
# run-tests-ubuntu-22_04-python-3_11_1:
# runs-on: ubuntu-22.04
# name: Ubuntu 22.04, Python 3.11.1
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-python@v4
# with:
# python-version: "3.11.1"
# - run: sudo apt install xvfb
# - run: pip install --upgrade pip
# - run: pip install .[dev]
# - run: xvfb-run pytest tests/

run-tests-ubuntu-22_04-python-3_11_2:
runs-on: ubuntu-22.04
name: Ubuntu 22.04, Python 3.11.2
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11.2"
- run: sudo apt install xvfb
- run: pip install --upgrade pip
- run: pip install .[dev]
- run: xvfb-run pytest tests/

run-tests-ubuntu-22_04-python-3_11:
runs-on: ubuntu-22.04
name: Ubuntu 22.04, Python 3.11
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- run: sudo apt install xvfb
- run: pip install --upgrade pip
- run: pip install .[dev]
- run: xvfb-run pytest tests/

# run-tests-ubuntu-22_04-python-3_12_0_alpha5:
# runs-on: ubuntu-22.04
# name: Ubuntu 22.04, Python 3.12.0alpha5
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-python@v4
# with:
# python-version: "3.12.0-alpha.5"
# - run: sudo apt install xvfb
# - run: pip install --upgrade pip
# - run: pip install .[dev]
# - run: xvfb-run pytest tests/
- run: xvfb-run pytest -v -rP --doctest-modules countess/ tests/

run-tests-ubuntu-22_04-python-3_11_from_apt:
runs-on: ubuntu-22.04
name: Ubuntu 22.04, Python from Apt
name: Ubuntu 22.04, Python 3.11 from Apt
steps:
- uses: actions/checkout@v4
- run: sudo apt install python3.11-full python3-pip xvfb
- run: python3.11 -m pip install --upgrade pip
- run: python3.11 -m pip install -e .[dev]
- run: xvfb-run python3.11 -mpytest tests/
- run: xvfb-run python3.11 -m pytest -v -rP --doctest-modules countess/ tests/

# run-tests-ubuntu-22_10-python-3_11_from_apt:
#runs-on: ubuntu-22.10
#name: Ubuntu 22.10, Python from Apt
#steps:
#- uses: actions/checkout@v4
#- run: sudo apt install python3.11-full python3-pip xvfb
#- run: python3.11 -m pip install --upgrade pip
#- run: python3.11 -m pip install -e .[dev]
#- run: xvfb-run python3.11 -mpytest tests/

#run-tests-ubuntu-23_04-python-3_11_from_apt:
#runs-on: ubuntu-23.04
#name: Ubuntu 23.04, Python from Apt
#steps:
#- uses: actions/checkout@v4
#- run: sudo apt install python3.11-full python3-pip xvfb
#- run: python3.11 -m pip install --upgrade pip
#- run: python3.11 -m pip install -e .[dev]
#- run: xvfb-run python3.11 -mpytest tests/
run-tests-ubuntu-24_04-python-3_12_from_apt:
runs-on: ubuntu-24.04
name: Ubuntu 24.04, Python 3.12 from Apt
steps:
- uses: actions/checkout@v4
- run: sudo apt install python3.12-full python3-pip xvfb
- run: python3.12 -m venv /tmp/venv
- run: /tmp/venv/bin/python -m pip install --upgrade pip
- run: /tmp/venv/bin/python -m pip install -e .[dev]
- run: xvfb-run /tmp/venv/bin/python -m pytest -v -rP --doctest-modules countess/ tests/

# run-tests-ubuntu-22_04-pypy3:
# runs-on: ubuntu-22.04
# name: Ubuntu 22.04, PyPy 3
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-python@v4
# with:
# python-version: "pypy3.9"
# - run: sudo apt install pypy3 pypy3-tk pypy3-dev xvfb
# - run: pypy3 -mpip install -U pip wheel
# - run: pypy3 -mpip install .[dev]
# - run: xvfb-run pytest tests/
run-tests-ubuntu-24_04-python-3_x:
runs-on: ubuntu-24.04
name: Ubuntu 24.04, Python 3.x
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.x"
cache: 'pip'
- run: sudo apt install xvfb
- run: python3 -m venv /tmp/venv
- run: /tmp/venv/bin/python -m pip install --upgrade pip
- run: /tmp/venv/bin/python -m pip install -e .[dev]
- run: xvfb-run /tmp/venv/bin/coverage run --source countess -m pytest -v -rP --doctest-modules countess/ tests/
- run: echo '### Coverage Report' >> $GITHUB_STEP_SUMMARY
- run: /tmp/venv/bin/coverage report --format=markdown --skip-empty --sort=-cover >> $GITHUB_STEP_SUMMARY
24 changes: 17 additions & 7 deletions countess/core/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,27 @@ def run(argv) -> None:


def main() -> None:
# set up a default stderr StreamHandler for logs
logging_handler = logging.StreamHandler()

# set up a QueueHandler/QueueListener to forward the logs between
# processes and send them to the logging_handler
logging_queue: multiprocessing.Queue = multiprocessing.Queue()
logging.getLogger().addHandler(logging.handlers.QueueHandler(logging_queue))
logging.getLogger().setLevel(logging.INFO)
logging_handler = logging.handlers.QueueListener(logging_queue, logging.StreamHandler())
logging_handler.start()
logging_queue_handler = logging.handlers.QueueHandler(logging_queue)
logging_queue_listener = logging.handlers.QueueListener(logging_queue, logging_handler)
logging_queue_listener.start()

# set up all loggers to be handled by the QueueHandler.
root_logger = logging.getLogger()
root_logger.addHandler(logging_queue_handler)
root_logger.setLevel(logging.INFO)

run(sys.argv[1:])

# tidy up just in case we're not just about to exit
logging.getLogger().handlers.clear()
logging_handler.stop()
# shut down the logging subsystem, in case this function is being
# called as part of something else (eg: tests)
root_logger.handlers.clear()
logging_queue_listener.stop()
logging_queue.close()


Expand Down
65 changes: 32 additions & 33 deletions countess/core/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ def __ne__(self, other):
def __gt__(self, other):
return self._value > other

def __gte__(self, other):
def __ge__(self, other):
return self._value >= other

def __lt__(self, other):
return self._value < other

def __lte__(self, other):
def __le__(self, other):
return self._value <= other


Expand Down Expand Up @@ -187,6 +187,15 @@ def __int__(self):
def __float__(self):
return float(self._value)

def __abs__(self):
return abs(self._value)

def __pos__(self):
return self._value

def __neg__(self):
return 0 - (self._value)

# XXX should include many more numeric operator methods here, see
# https://docs.python.org/3/reference/datamodel.html#emulating-numeric-types
# matmul, truediv, floordiv, mod, divmod, pow, lshift, rshift, and, xor, or,
Expand Down Expand Up @@ -219,10 +228,12 @@ def set_value(self, value):
if isinstance(value, str):
if value in ("t", "T", "true", "True", "1"):
self._value = True
if value in ("f", "F", "false", "False", "0"):
elif value in ("f", "F", "false", "False", "0"):
self._value = False
raise ValueError(f"Can't convert {value} to boolean")
self._value = bool(value)
else:
raise ValueError(f"Can't convert {value} to boolean")
else:
self._value = bool(value)

def __bool__(self):
return self._value or False
Expand Down Expand Up @@ -402,10 +413,10 @@ def __init__(self, label: str, value: Optional[str] = None, choices: Optional[It
super().__init__(label, value, choices)

def get_selected_type(self):
if self.value is None:
return None
else:
try:
return self.DATA_TYPES[self.value][0]
except KeyError:
return None

def cast_value(self, value):
if value is not None:
Expand Down Expand Up @@ -519,7 +530,7 @@ def is_not_none(self):
def get_column_prefix(self):
if self.is_none():
return None
return self.value.removesuffix("*")
return super().get_column_prefix()


class ColumnOrIndexChoiceParam(ColumnChoiceParam):
Expand Down Expand Up @@ -548,33 +559,32 @@ class ColumnOrStringParam(ColumnChoiceParam):
def set_column_choices(self, choices):
self.set_choices([self.PREFIX + c for c in choices])

def get_column_name(self):
if self.value.startswith(self.PREFIX):
def get_column_name(self) -> Optional[str]:
if type(self.value) is str and self.value.startswith(self.PREFIX):
return self.value[len(self.PREFIX) :]
return None

def get_value_from_dict(self, data: dict):
def get_value_from_dict(self, data: dict) -> str:
if type(self.value) is str and self.value.startswith(self.PREFIX):
return data[self.value[len(self.PREFIX) :]]
else:
return self.value

def get_column_or_value(self, df: pd.DataFrame, numeric: bool):
if self.value.startswith(self.PREFIX):
def get_column_or_value(self, df: pd.DataFrame, numeric: bool) -> Union[float, str, pd.Series]:
if type(self.value) is str and self.value.startswith(self.PREFIX):
col = df[self.value[len(self.PREFIX) :]]
return col.astype("f" if numeric else "string")
return col.astype(float if numeric else str)
else:
return float(self.value) if numeric else str(self.value)

def get_column_or_value_numeric(self, df: pd.DataFrame):
if self.value.startswith(self.PREFIX):
return df[self.value[len(self.PREFIX) :]]
else:
return self.value

def set_choices(self, choices: Iterable[str]):
self.choices = list(choices)
if self._value is not None and self._value.startswith(self.PREFIX) and self._value not in self.choices:
if (
self._value is not None
and type(self._value) is str
and self._value.startswith(self.PREFIX)
and self._value not in self.choices
):
self._value = self.DEFAULT_VALUE
self._choice = None

Expand Down Expand Up @@ -862,17 +872,6 @@ def copy(self) -> "MultiParam":
pp = dict(((k, p.copy()) for k, p in self.params.items()))
return self.__class__(self.label, pp)

# XXX decide if these "dict-like" accessors are worth keeping

def __getitem__(self, key):
return self.params[key]

def __contains__(self, item):
return item in self.params

def __setitem__(self, key, value):
self.params[key].value = value

def __iter__(self):
return self.params.__iter__()

Expand Down
Loading

0 comments on commit 3ef5c5f

Please sign in to comment.