Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atomic transformations #11

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions .github/workflows/docs-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,32 @@ on:
branches:
- master
- main
workflow_dispatch:
inputs:
whotriggered:
description: 'Manually Build Docs'
default: 'Just want to build it'
required: false

permissions:
contents: write

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Setup Poetry
uses: abatilo/actions-poetry@v2
with:
python-version: 3.x
- run: pip install mkdocs
- run: pip install mkdocs-material
- run: pip install mkdocs-material-extensions
- run: pip install mkdocs-autorefs
- run: pip install mkdocstrings
- run: pip install -e ".[all]"
- run: mkdocs gh-deploy --force
poetry-version: 1.3.2
- name: Install Packages
run: poetry install
- run: git config user.name 'github-actions[bot]' && git config user.email 'github-actions[bot]@users.noreply.github.com'
- name: Deploy
run: poetry run mkdocs gh-deploy --force
9 changes: 6 additions & 3 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
name: Build and Publish Package to Pypi

on:
push:
branches:
- "main"
workflow_dispatch:
inputs:
name:
description: 'release it'
required: false
default: 'I Just wanna release it'

jobs:
tests:
Expand Down
76 changes: 50 additions & 26 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test Code with Pip
name: Test Code

on:
push:
Expand All @@ -15,40 +15,64 @@ on:
required: false
default: 'I Just wanna test it'

permissions:
contents: read
issues: read
checks: write
pull-requests: write

jobs:
build:
test:
strategy:
matrix:
python-version: [3.7, 3.8]
python-version: [3.9.16, 3.10.8]
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install from source (required for the pre-commit tests)
run: pip install ".[all]"
- name: Install dependencies
- name: Setup Poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: 1.3.2
- name: Install
run: poetry install --with test,docs,aws
- name: Build coverage file
run: |
# python -m pip install --upgrade pip
# pip install -r requirements.txt
# install black if available (Python 3.6 and above), and autopep8 for testing the pipe mode
pip install black || true
pip install autopep8 || true
- name: Lint with flake8
poetry run pytest --cache-clear --junitxml=test_results/${{ matrix.os }}/pytest_report_${{ matrix.python-version }}.xml tests/
- name: Check files
run: |
pip install flake8==3.8.3
pip install flake8-black==0.2.1
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# all Python files should follow PEP8
# echo "flake8 all python"
# flake8 durst tests
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
echo "flake8 BLK"
flake8 durst --count --exit-zero --max-complexity=18 --statistics --select BLK
- name: Test with pytest
run: nosetests
ls -l test_results/
ls -l test_results/${{ matrix.os }}/
- name: Upload Test Results
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: pytest-results-${{ matrix.python-version }}
path: test_results/${{ matrix.os }}/pytest_report_${{ matrix.python-version }}.xml
# - name: Comment coverage
# uses: coroo/[email protected]

publish-test-results:
name: "Publish Tests Results"
needs: test
runs-on: ubuntu-latest
# the build-and-test job might be skipped, we don't need to run this job then
if: success() || failure()

steps:
- name: Download Artifacts
uses: actions/download-artifact@v2
with:
path: artifacts
- name: Check files
run: |
ls -l artifacts/
- name: Publish test results
uses: EnricoMi/publish-unit-test-result-action@v2
with:
junit_files: "artifacts/**/*.xml"
Empty file added haferml/transforms/__init__.py
Empty file.
52 changes: 52 additions & 0 deletions haferml/transforms/dataframe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from __future__ import annotations
from abc import ABC, abstractmethod
import pandas as pd
from typing import List, Union


class TransformBase(ABC):
"""
TransformBase transforms a dataframe.

This is a transformation inspired by the
package gluonts.
"""

@abstractmethod
def __call__(self, dataframe: pd.DataFrame) -> pd.DataFrame:
"""
"""
raise NotImplementedError("This method is not implemented yet.")

def __add__(self, other: TransformBase) -> ConcatTransform:
"""
"""
return ConcatTransform([self, other])


class ConcatTransform(TransformBase):
"""Concatenated transforms.

The returned transforms inherited from the

:param transforms: List of transforms to be concatenated
"""

def __init__(self, transforms: List[TransformBase]):
self.transforms = []
for transform in transforms:
self._update(transform)

def _update(self, transform: Union[ConcatTransform, TransformBase]):
if isinstance(transform, ConcatTransform):
self.transforms.extend(transform)
elif isinstance(transform, TransformBase):
self.transforms.append(transform)
else:
raise TypeError("Expected type TransformBase or ConcatTransform")

def __call__(self, dataframe: pd.DataFrame) -> pd.DataFrame:
for t in self.transforms:
dataframe = t(dataframe)

return dataframe
Loading
Loading