From e2097e9ec12f84f66587b09ff01843ea6fd58825 Mon Sep 17 00:00:00 2001 From: IanCa Date: Wed, 26 Jun 2024 11:42:40 -0500 Subject: [PATCH] Fix np.nan, add windows CI workflow --- .github/workflows/ci_windows.yaml | 42 +++++++++++++++++++ hed/tools/analysis/annotation_util.py | 4 +- hed/tools/remodeling/dispatcher.py | 2 +- .../remodeling/operations/remap_columns_op.py | 2 +- tests/tools/analysis/test_annotation_util.py | 10 ++--- 5 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/ci_windows.yaml diff --git a/.github/workflows/ci_windows.yaml b/.github/workflows/ci_windows.yaml new file mode 100644 index 00000000..278271b9 --- /dev/null +++ b/.github/workflows/ci_windows.yaml @@ -0,0 +1,42 @@ +name: CI + +on: + push: + branches: ["main", "master"] + pull_request: + branches: ["main", "master"] + +jobs: + build: + strategy: + matrix: + platform: [windows-latest] + python-version: ["3.10"] + + runs-on: ${{ matrix.platform }} + + steps: + - uses: actions/checkout@v4 + with: + submodules: false + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - uses: actions/cache@v4 + with: + path: ${{ env.pythonLocation }} + key: ${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ hashFiles('docs/requirements.txt') }} + + - name: Install dependencies + run: | + python -m pip install --upgrade --upgrade-strategy eager pip + pip install -r requirements.txt + + - name: Test with unittest + env: + HED_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + python -m unittest diff --git a/hed/tools/analysis/annotation_util.py b/hed/tools/analysis/annotation_util.py index 015c2336..3b91efe4 100644 --- a/hed/tools/analysis/annotation_util.py +++ b/hed/tools/analysis/annotation_util.py @@ -199,7 +199,7 @@ def series_to_factor(series): series (Series) - Series to be converted to a list. Returns: - list - contains 0's and 1's, empty, 'n/a' and np.NAN are converted to 0. + list - contains 0's and 1's, empty, 'n/a' and np.nan are converted to 0. """ replaced = series.replace('n/a', False) filled = replaced.fillna(False) @@ -273,7 +273,7 @@ def to_factor(data, column=None): column (str): Optional column name if DataFrame (otherwise column 0). Returns: - list - contains 0's and 1's, empty, 'n/a' and np.NAN are converted to 0. + list - contains 0's and 1's, empty, 'n/a' and np.nan are converted to 0. """ if isinstance(data, Series): series = data diff --git a/hed/tools/remodeling/dispatcher.py b/hed/tools/remodeling/dispatcher.py index cd6b81c3..04e6d809 100644 --- a/hed/tools/remodeling/dispatcher.py +++ b/hed/tools/remodeling/dispatcher.py @@ -219,7 +219,7 @@ def post_proc_data(df): df (DataFrame): The DataFrame to be processed. Returns: - DataFrame: DataFrame with the 'np.NAN replaced by 'n/a'. + DataFrame: DataFrame with the 'np.nan replaced by 'n/a'. """ dtypes = df.dtypes.to_dict() diff --git a/hed/tools/remodeling/operations/remap_columns_op.py b/hed/tools/remodeling/operations/remap_columns_op.py index ea98d03c..d9d84215 100644 --- a/hed/tools/remodeling/operations/remap_columns_op.py +++ b/hed/tools/remodeling/operations/remap_columns_op.py @@ -134,7 +134,7 @@ def do_op(self, dispatcher, df, name, sidecar=None): """ df1 = df.copy() df1[self.source_columns] = df1[self.source_columns].replace( - np.NaN, 'n/a') + np.nan, 'n/a') for column in self.integer_sources: int_mask = df1[column] != 'n/a' df1.loc[int_mask, column] = df1.loc[int_mask, column].astype(int) diff --git a/tests/tools/analysis/test_annotation_util.py b/tests/tools/analysis/test_annotation_util.py index 384419d3..dfbea0f8 100644 --- a/tests/tools/analysis/test_annotation_util.py +++ b/tests/tools/analysis/test_annotation_util.py @@ -300,13 +300,13 @@ def test_to_factor(self): factor1 = annotation_util.to_factor(series1) self.assertEqual(len(series1), len(factor1)) self.assertEqual(sum(factor1), len(factor1)) - series2 = Series(['a', '', None, np.NAN, 'n/a']) + series2 = Series(['a', '', None, np.nan, 'n/a']) factor2 = annotation_util.to_factor(series2) self.assertEqual(len(series2), len(factor2)) self.assertEqual(sum(factor2), 1) data = { 'Name': ['Alice', '', 'n/a', 1.0], # Contains a space - 'Age': [25, np.NaN, 35, 0] + 'Age': [25, np.nan, 35, 0] } df = DataFrame(data) factor3 = annotation_util.to_factor(df, column='Name') @@ -321,7 +321,7 @@ def test_series_to_factor(self): factor1 = annotation_util.series_to_factor(series1) self.assertEqual(len(series1), len(factor1)) self.assertEqual(sum(factor1), len(factor1)) - series2 = Series(['a', '', None, np.NAN, 'n/a']) + series2 = Series(['a', '', None, np.nan, 'n/a']) factor2 = annotation_util.series_to_factor(series2) self.assertEqual(len(series2), len(factor2)) self.assertEqual(sum(factor2), 1) @@ -465,13 +465,13 @@ def test_to_factor(self): factor1 = annotation_util.to_factor(series1) self.assertEqual(len(series1), len(factor1)) self.assertEqual(sum(factor1), len(factor1)) - series2 = Series(['a', '', None, np.NAN, 'n/a']) + series2 = Series(['a', '', None, np.nan, 'n/a']) factor2 = annotation_util.to_factor(series2) self.assertEqual(len(series2), len(factor2)) self.assertEqual(sum(factor2), 1) data = { 'Name': ['Alice', '', 'n/a', 1.0], # Contains a space - 'Age': [25, np.NaN, 35, 0] + 'Age': [25, np.nan, 35, 0] } df = DataFrame(data) factor3 = annotation_util.to_factor(df, column='Name')