Skip to content

Commit

Permalink
try ci
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Oct 11, 2023
1 parent d5422e5 commit 56df508
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 28 deletions.
125 changes: 101 additions & 24 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,120 @@
# This file is autogenerated by maturin v1.3.0
# To update, run
#
# maturin generate-ci github -m src/expression_lib/Cargo.toml
#
name: CI

on:
pull_request:
push:
branches:
- main
- master
tags:
- '*'
pull_request:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
permissions:
contents: read

jobs:
test:
runs-on: ${{ matrix.os }}
linux:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
target: [x86_64, x86, aarch64, armv7, s390x, ppc64le]
steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Set up Rust
run: rustup show
python-version: '3.10'
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter --manifest-path src/expression_lib/Cargo.toml
sccache: 'true'
manylinux: auto
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist

- uses: mozilla-actions/[email protected]
windows:
runs-on: windows-latest
strategy:
matrix:
target: [x64, x86]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
architecture: ${{ matrix.target }}
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter --manifest-path src/expression_lib/Cargo.toml
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist

- run: cargo test
working-directory: pyo3-polars
macos:
runs-on: macos-latest
strategy:
matrix:
target: [x86_64, aarch64]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter --manifest-path src/expression_lib/Cargo.toml
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist

- run: make install
working-directory: example/extend_polars_python_dispatch
sdist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build sdist
uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist --manifest-path src/expression_lib/Cargo.toml
- name: Upload sdist
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist

- run: venv/bin/python run.py
working-directory: example/extend_polars_python_dispatch
release:
name: Release
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/')"
needs: [linux, windows, macos, sdist]
steps:
- uses: actions/download-artifact@v3
with:
name: wheels
- name: Publish to PyPI
uses: PyO3/maturin-action@v1
env:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
with:
command: upload
args: --non-interactive --skip-existing *
4 changes: 2 additions & 2 deletions src/expression_lib/expression_lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ def __init__(self, expr: pl.Expr):
self._expr = expr.cast(pl.Int32)


def add_bday(self, n) -> pl.Expr:
def advance_by_days(self, n) -> pl.Expr:
if not (isinstance(n, int) and n > 0):
raise ValueError("only positive integers are currently supported for `n`")

return self._expr._register_plugin(
lib=lib,
symbol="add_bday",
symbol="advance_by_days",
is_elementwise=True,
args = [n],
)
2 changes: 1 addition & 1 deletion src/expression_lib/src/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use polars::prelude::*;
use pyo3_polars::derive::polars_expr;

#[polars_expr(output_type=Date)]
fn add_bday(inputs: &[Series]) -> PolarsResult<Series> {
fn advance_by_days(inputs: &[Series]) -> PolarsResult<Series> {
let ca = inputs[0].i32()?;
let n = inputs[1].i32()?.get(0).unwrap();

Expand Down
2 changes: 1 addition & 1 deletion src/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
})
df = df.filter(pl.col('dates').dt.weekday() <6)

print(df.with_columns(dates_shifted=pl.col('dates').bdt.add_bday(n=15))[20:28])
print(df.with_columns(dates_shifted=pl.col('dates').bdt.advance_by_days(n=15))[20:28])
print(df.with_columns(dates_shifted=pl.Series(np.busday_offset(df['dates'], 15)))[20:28])

import pandas as pd
Expand Down

0 comments on commit 56df508

Please sign in to comment.