Skip to content

Commit

Permalink
Fix np.nan, add windows CI workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
IanCa committed Jun 26, 2024
1 parent 0ef01a1 commit e2097e9
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 9 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/ci_windows.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions hed/tools/analysis/annotation_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion hed/tools/remodeling/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion hed/tools/remodeling/operations/remap_columns_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions tests/tools/analysis/test_annotation_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit e2097e9

Please sign in to comment.