Skip to content

Commit

Permalink
Merge pull request #131 from maxsch3/update_versions
Browse files Browse the repository at this point in the history
Update versions and resolve vulnerabilities
  • Loading branch information
maxsch3 authored Dec 24, 2023
2 parents 2d36fad + 7c36ebb commit 911d5c5
Show file tree
Hide file tree
Showing 23 changed files with 255 additions and 50 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/master-pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Python package

on:
push:
branches:
- 'master'


jobs:
test-code:
name: "Test code"

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Test with pytest
run: |
pip install pytest pytest-cov pytest-dependency
PYTHONPATH="$PYTHONPATH:./keras-batchflow" pytest tests --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
page_build:
name: "Build and deploy documentation to staging"
needs: test-code
runs-on: ubuntu-latest
environment: github-pages-staging
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r build_requirements.txt
pip install -e .
- name: Build docs
run: |
mkdocs build --verbose --clean --strict
- name: Deploy
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages # The branch the action should deploy to.
folder: site
repository-name: maxsch3/keras-batchflow-test
ssh-key: ${{ secrets.GH_DEPLOY_SECRET }}
102 changes: 102 additions & 0 deletions .github/workflows/release-pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Python package

on:
release:
types: ['published']


jobs:

page_build:
name: "Build documentation"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade build
pip install -r requirements.txt
pip install -r build_requirements.txt
pip install -e .
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Build docs
run: |
mkdocs build --verbose --clean --strict
- name: Upload page artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./site

pypi_build:
name: Build pypi package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade build
pip install -r requirements.txt
pip install -r build_requirements.txt
pip install -e .
- name: Build pypi package
run: |
python -m build
- name: Upload build package as artifact
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/

deploy_page:
name: 'Deploy release documentation'
needs: [page_build, pypi_build]

# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source
actions: read # to download an artifact uploaded by `actions/upload-pages-artifact@v3`

# Deploy to the github-pages environment
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

# Specify runner + deployment step
runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

deploy_pypi:
name: Publish to pypi
needs: [page_build, pypi_build]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/keras-batchflow
permissions:
id-token: write
steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
50 changes: 50 additions & 0 deletions .github/workflows/test-pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Python package

on:
push:
branches:
- '*'
- '!master'

jobs:
test-code:
name: "Test code"

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Test with pytest
run: |
pip install pytest pytest-cov pytest-dependency
PYTHONPATH="$PYTHONPATH:./keras-batchflow" pytest tests --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
test-doc-build:
name: "Test documentation build"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r build_requirements.txt
pip install -e .
- name: Test doc build
run: |
mkdocs build --verbose --clean --strict
14 changes: 6 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
language: python
python:
# - "2.7"
# - "3.4"
# - "3.5"
- "3.6"
- "3.7"
- "3.8"
- "3.9"
- "3.10"
env:
- framework=TF1
# - framework=TF1
- framework=TF2

script:
Expand All @@ -16,7 +14,7 @@ jobs:
include:
- stage: deploy-test
if: branch = master
python: "3.6"
python: "3.10"
script: skip
install:
- pip install -r requirements_tf1.txt
Expand All @@ -34,7 +32,7 @@ jobs:
branch: master
- stage: deploy-prod
if: tag IS present
python: "3.6"
python: "3.10"
script: skip
install:
- pip install -r requirements_tf1.txt
Expand Down
12 changes: 6 additions & 6 deletions build_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
setuptools-scm==3.5.0
mkdocs==1.1.2
mkdocs-jupyter==0.13.0
notebook==6.1.5
pymdown-extensions==6.3
nbconvert==5.6.1
setuptools-scm
mkdocs
mkdocs-jupyter
notebook
pymdown-extensions
nbconvert
git+https://github.com/tomchristie/mkautodoc.git#egg=mkautodoc
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pandas>=2.0.0
scikit-learn
tensorflow-cpu
8 changes: 0 additions & 8 deletions requirements_tf1.txt

This file was deleted.

7 changes: 0 additions & 7 deletions requirements_tf2.txt

This file was deleted.

7 changes: 3 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
download_url='https://github.com/maxsch3/batchflow',
license='MIT',
setup_requires=['setuptools_scm'],
install_requires=['numpy>=1.9.1',
'scipy>=0.14',
install_requires=['numpy>=1.20.0',
'scikit-learn',
'pandas'],
'pandas>=2.0.0'],
extras_require={
'visualize': ['pydot>=1.2.4'],
'tests': ['pytest',
Expand All @@ -33,7 +32,7 @@
'Intended Audience :: Science/Research',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.10',
'Topic :: Software Development :: Libraries',
'Topic :: Software Development :: Libraries :: Python Modules'
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,15 @@ def test_transform(self):

def test_transform_many_cols(self):
ct = LocalVersionTransform([.0, 1.], cols=['var1', 'var2'])
batch = ct.transform(self.df.copy())
# make a bigger batch to make sure augmenatation will always be used on the batch
# when batch is small there is a small chance the batch will sieve through without augmentation due to its
# random nature
seed_df = self.df.sample(100, replace=True)
batch = ct.transform(seed_df.copy())
assert isinstance(batch, pd.DataFrame)
assert batch.shape == self.df.shape
assert not batch.equals(self.df)
batch = self.df.copy()
assert batch.shape == seed_df.shape
assert not batch.equals(seed_df)
batch = seed_df.copy()
batch1 = ct.transform(batch)
# test if transform does in-place transform
assert batch1.equals(batch)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 12 additions & 9 deletions test/test_feature_dropout.py → tests/test_feature_dropout.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,19 @@ def test_row_dist(self):
assert binom_test(b, 1000, 0.6) > 0.01

def test_cols_dist(self):
sample_size = 1000
fd = FeatureDropout([0., 1.], ['var1', 'var2', 'label'], drop_values='', col_probs=[.5, .3, .2])
batch = fd.transform(self.df.sample(1000, replace=True))
batch = fd.transform(self.df.sample(sample_size, replace=True))
b = (batch == '').sum(axis=0)
c, p = chisquare(b, [520, 300, 180])
c, p = chisquare(b, [sample_size * .53, sample_size * .3, sample_size * .17])
assert p > 0.001

def test_uniform_col_dist(self):
sample_size = 1000
fd = FeatureDropout([0., 1.], ['var1', 'var2', 'label'], drop_values='')
batch = fd.transform(self.df.sample(1000, replace=True))
batch = fd.transform(self.df.sample(sample_size, replace=True))
b = (batch == '').sum(axis=0)
c, p = chisquare(b, [333, 333, 333])
c, p = chisquare(b, f_exp=[sample_size/3, sample_size/3, sample_size/3])
assert p > 0.01

def test_different_drop_values(self):
Expand All @@ -55,20 +57,21 @@ def test_different_drop_values(self):
assert b[1] == 0
assert b[2] == 0
b = (batch == 'v2').sum(axis=0)
assert binom_test(b[1], 1000, 0.33) > 0.01
assert binom_test(b[1], 1000, 0.33) > 0.001
assert b[0] == 0
assert b[2] == 0
b = (batch == 'v3').sum(axis=0)
assert binom_test(b[2], 1000, 0.33) > 0.01
assert binom_test(b[2], 1000, 0.33) > 0.001
assert b[0] == 0
assert b[1] == 0

def test_multiple_feature_drop(self):
sample_size = 100
fd = FeatureDropout([0., .7, .3], ['var1', 'var2', 'label'], drop_values='', col_probs=[.5, .3, .2])
batch = fd.transform(self.df.sample(1000, replace=True))
batch = fd.transform(self.df.sample(sample_size, replace=True))
b = (batch == '').sum(axis=1).value_counts().sort_index().tolist()
c, p = chisquare(b, [700, 300])
assert p > 0.01
c, p = chisquare(b, [sample_size * .7, sample_size * .3])
assert p > 0.001

def test_parameter_error_handling(self):
# column name is not str
Expand Down
Loading

0 comments on commit 911d5c5

Please sign in to comment.