From 6b2c6d086c56bc55650507352473bb3368342acf Mon Sep 17 00:00:00 2001 From: Tomoki Ohtsuki Date: Fri, 1 Jul 2022 07:44:10 +0900 Subject: [PATCH] Fix Issue #13 (#14) * Fix #13. * Fix run-test for C++ coverage. --- .github/workflows/run-test.yml | 3 ++- src/myfm/utils/encoders/categorical.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/run-test.yml b/.github/workflows/run-test.yml index 223ffa1..cfa65e4 100644 --- a/.github/workflows/run-test.yml +++ b/.github/workflows/run-test.yml @@ -18,7 +18,8 @@ jobs: pip install --upgrade pip pip install numpy scipy pandas sudo apt-get install lcov - CXXFLAGS="-O0 -g -coverage" pip install -e . + FLAGS="-fprofile-arcs -ftest-coverage" + CFLAGS="$FLAGS" CXXFLAGS="$FLAGS" pip install -e . - name: Run pytest run: | pip install pytest pytest-cov pytest-mock diff --git a/src/myfm/utils/encoders/categorical.py b/src/myfm/utils/encoders/categorical.py index 1cfb4b3..c663b56 100644 --- a/src/myfm/utils/encoders/categorical.py +++ b/src/myfm/utils/encoders/categorical.py @@ -57,6 +57,12 @@ def _get_index(self, x: T) -> Optional[int]: return None raise + def __getitem__(self, x: T) -> int: + result = self._get_index(x) + if result is None: + raise KeyError(f"{x} not found.") + return result + def names(self) -> List[str]: return [str(y) for y in self.values]