Skip to content

Commit

Permalink
Merge pull request #76 from pola-rs/bump-version
Browse files Browse the repository at this point in the history
Bump version
  • Loading branch information
MarcoGorelli authored May 30, 2024
2 parents b490787 + 910abaa commit df47882
Show file tree
Hide file tree
Showing 20 changed files with 200 additions and 141 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
run: rustup show
- uses: mozilla-actions/[email protected]
- run: make venv
- run: venv/bin/python -m pip install polars==0.20.6 # min version
- run: .venv/bin/python -m pip install polars==0.20.6 # min version
- run: make install
- run: make test

Expand Down
18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "polars_xdt"
version = "0.14.12"
version = "0.14.13"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -9,15 +9,15 @@ name = "polars_xdt"
crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = "0.20.0", features = ["extension-module", "abi3-py38"] }
pyo3-polars = { version = "0.12.0", features = ["derive"] }
pyo3 = { version = "0.21.2", features = ["extension-module", "abi3-py38"] }
pyo3-polars = { version = "0.14.0", features = ["derive"] }
serde = { version = "1", features = ["derive"] }
chrono = { version = "0.4.31", default-features = false, features = ["std", "unstable-locales"] }
chrono-tz = "0.8.5"
polars = { version = "0.38.2", features = ["strings", "dtype-date"], default-features = false }
polars-time = { version = "0.38.2", features = ["timezones"], default-features = false }
polars-ops = { version = "0.38.2", default-features = false }
polars-arrow = { version = "0.38.2", default-features = false }
chrono = { version = "0.4.38", default-features = false, features = ["std", "unstable-locales"] }
chrono-tz = "0.9.0"
polars = { version = "0.40.0", features = ["strings", "dtype-date"], default-features = false }
polars-time = { version = "0.40.0", features = ["timezones"], default-features = false }
polars-ops = { version = "0.40.0", default-features = false }
polars-arrow = { version = "0.40.0", default-features = false }

[target.'cfg(target_os = "linux")'.dependencies]
jemallocator = { version = "0.5", features = ["disable_initial_exec_tls"] }
22 changes: 11 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@
SHELL=/bin/bash

venv: ## Set up virtual environment
python3 -m venv venv
venv/bin/pip install -r requirements.txt -r docs/requirements-docs.txt
python3 -m venv .venv
.venv/bin/pip install -r requirements.txt -r docs/requirements-docs.txt

install: venv
unset CONDA_PREFIX && \
source venv/bin/activate && maturin develop
source .venv/bin/activate && maturin develop

install-release: venv
unset CONDA_PREFIX && \
source venv/bin/activate && maturin develop --release
source .venv/bin/activate && maturin develop --release

pre-commit: venv
cargo fmt --all && cargo clippy --all-features
venv/bin/python -m ruff check . --fix --exit-non-zero-on-fix
venv/bin/python -m ruff format polars_xdt tests
venv/bin/python -m mypy polars_xdt tests
.venv/bin/python -m ruff check polars_xdt tests --fix --exit-non-zero-on-fix
.venv/bin/python -m ruff format polars_xdt tests
.venv/bin/python -m mypy polars_xdt tests

test: venv
venv/bin/python -m pytest tests
venv/bin/python -m pytest polars_xdt --doctest-modules
.venv/bin/python -m pytest tests
.venv/bin/python -m pytest polars_xdt --doctest-modules

run: install
source venv/bin/activate && python run.py
source .venv/bin/activate && python run.py

run-release: install-release
source venv/bin/activate && python run.py
source .venv/bin/activate && python run.py
30 changes: 29 additions & 1 deletion polars_xdt/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import re
import sys
import warnings
from datetime import date, timedelta
from pathlib import Path
from typing import TYPE_CHECKING, Literal, Sequence
Expand Down Expand Up @@ -58,6 +59,10 @@ def offset_by(
"""
Offset this date by a relative time offset.
.. deprecated:: 0.14.13
This is deprecated, please use `polars.add_business_days` instead.
Parameters
----------
expr
Expand Down Expand Up @@ -153,14 +158,19 @@ def offset_by(
└────────────┴──────┴──────────────┘
"""
warnings.warn(
"`offset_by` is deprecated, as it has been upstreamed. Please use `polars.add_business_days` instead.",
DeprecationWarning,
stacklevel=2,
)
expr = parse_into_expr(expr)
if (
isinstance(by, str)
and (match := re.search(r"(\d+bd)", by)) is not None
and (len(match.group(1)) == len(by))
):
# Fast path - do we have a business day offset, and nothing else?
n: int | pl.Expr = int(by[:-2])
n: int | pl.Expr = pl.lit(int(by[:-2]), dtype=pl.Int32)
fastpath = True
else:
if not isinstance(by, pl.Expr):
Expand Down Expand Up @@ -677,6 +687,10 @@ def workday_count(
"""
Count the number of workdays between two columns of dates.
.. deprecated:: 0.14.13
This is deprecated, please use `polars.business_day_count` instead.
Parameters
----------
start_dates
Expand Down Expand Up @@ -717,6 +731,11 @@ def workday_count(
└────────────┴────────────┴─────────────────┘
"""
warnings.warn(
"`workday_count` is deprecated, as it has been upstreamed. Please use `polars.business_day_count` instead.",
DeprecationWarning,
stacklevel=2,
)
start_dates = parse_into_expr(start_dates)
end_dates = parse_into_expr(end_dates)
weekmask = get_weekmask(weekend)
Expand Down Expand Up @@ -926,6 +945,10 @@ def ewma_by_time(
where :math:`\lambda` equals :math:`\ln(2) / \text{half_life}`.
.. deprecated:: 0.14.13
This is deprecated, please use `polars.ewm_mean_by` instead.
Parameters
----------
values
Expand Down Expand Up @@ -976,6 +999,11 @@ def ewma_by_time(
└────────┴────────────┴──────────┘
"""
warnings.warn(
"`ewma_by_time` is deprecated, as it has been upstreamed. Please use `polars.ewm_mean_by` instead.",
DeprecationWarning,
stacklevel=2,
)
values = parse_into_expr(values)
half_life_us = (
int(half_life.total_seconds()) * 1_000_000 + half_life.microseconds
Expand Down
9 changes: 3 additions & 6 deletions polars_xdt/ranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ def date_range(
eager: Literal[False] = ...,
weekend: Sequence[str] = ...,
holidays: Sequence[date] | None = ...,
) -> pl.Expr:
...
) -> pl.Expr: ...


@overload
Expand All @@ -41,8 +40,7 @@ def date_range(
eager: Literal[True],
weekend: Sequence[str] = ...,
holidays: Sequence[date] | None = ...,
) -> pl.Series:
...
) -> pl.Series: ...


@overload
Expand All @@ -57,8 +55,7 @@ def date_range(
eager: bool = ...,
weekend: Sequence[str] = ...,
holidays: Sequence[date] | None = ...,
) -> pl.Series | pl.Expr:
...
) -> pl.Series | pl.Expr: ...


def date_range( # noqa: PLR0913
Expand Down
14 changes: 8 additions & 6 deletions src/business_days.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ pub(crate) fn impl_advance_n_days(
let out = match n.len() {
1 => {
if let Some(n) = n.get(0) {
ca.try_apply(|x_date| {
ca.try_apply_nonnull_values_generic(|x_date| {
let x_weekday = weekday(x_date);
calculate_advance(
x_date, n, x_weekday, weekmask, n_weekdays, &holidays, roll,
Expand Down Expand Up @@ -188,13 +188,15 @@ pub(crate) fn impl_advance_n_days(
let out = match n.len() {
1 => {
if let Some(n) = n.get(0) {
ca.try_apply(|x| {
ca.try_apply_nonnull_values_generic(|x| {
let x_date = (x / multiplier) as i32;
let x_weekday = weekday(x_date);
Ok(x + ((calculate_advance(
x_date, n, x_weekday, weekmask, n_weekdays, &holidays, roll,
)? - x_date) as i64
* multiplier))
Ok::<i64, PolarsError>(
x + ((calculate_advance(
x_date, n, x_weekday, weekmask, n_weekdays, &holidays, roll,
)? - x_date) as i64
* multiplier),
)
})
} else {
Ok(Int64Chunked::full_null(ca.name(), ca.len()))
Expand Down
6 changes: 3 additions & 3 deletions src/ewma_by_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub(crate) fn impl_ewma_by_time_float(
times: &Int64Chunked,
values: &Float64Chunked,
half_life: i64,
time_unit: TimeUnit
time_unit: TimeUnit,
) -> Float64Chunked {
let mut out = Vec::with_capacity(times.len());
if values.is_empty() {
Expand All @@ -29,7 +29,7 @@ pub(crate) fn impl_ewma_by_time_float(
out.push(Some(prev_result));
skip_rows = idx + 1;
break;
},
}
_ => {
out.push(None);
}
Expand All @@ -50,7 +50,7 @@ pub(crate) fn impl_ewma_by_time_float(
prev_time = time;
prev_result = result;
out.push(Some(result));
},
}
_ => out.push(None),
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ fn arg_previous_greater(inputs: &[Series]) -> PolarsResult<Series> {

#[derive(Deserialize)]
struct EwmTimeKwargs {
half_life: i64
half_life: i64,
}

#[polars_expr(output_type=Float64)]
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod to_julian;
mod utc_offsets;

use pyo3::types::PyModule;
use pyo3::{pymodule, PyResult, Python};
use pyo3::{pymodule, Bound, PyResult};

#[cfg(target_os = "linux")]
use jemallocator::Jemalloc;
Expand All @@ -21,7 +21,7 @@ use jemallocator::Jemalloc;
static ALLOC: Jemalloc = Jemalloc;

#[pymodule]
fn _internal(_py: Python, m: &PyModule) -> PyResult<()> {
fn _internal(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add("__version__", env!("CARGO_PKG_VERSION"))?;
Ok(())
}
6 changes: 3 additions & 3 deletions src/timezone.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use arity::try_binary_elementwise;
use chrono::{LocalResult, NaiveDateTime, TimeZone};
use chrono_tz::Tz;
use polars::chunked_array::temporal::parse_time_zone;
use polars::prelude::*;
use polars_arrow::legacy::time_zone::Tz;
use pyo3_polars::export::polars_core::utils::arrow::legacy::kernels::Ambiguous;
use pyo3_polars::export::polars_core::utils::arrow::temporal_conversions::{
timestamp_ms_to_datetime, timestamp_ns_to_datetime, timestamp_us_to_datetime,
Expand Down Expand Up @@ -117,9 +117,9 @@ pub fn elementwise_from_local_datetime(
1 => match unsafe { from_tz.get_unchecked(0) } {
Some(from_tz) => {
let from_tz = parse_time_zone(from_tz)?;
datetime.0.try_apply(|timestamp| {
datetime.0.try_apply_nonnull_values_generic(|timestamp| {
let ndt = timestamp_to_datetime(timestamp);
Ok(datetime_to_timestamp(
Ok::<i64, PolarsError>(datetime_to_timestamp(
naive_local_to_naive_utc_in_new_time_zone(&from_tz, &to_tz, ndt, &ambig)?,
))
})
Expand Down
Empty file added tests/__init__.py
Empty file.
2 changes: 2 additions & 0 deletions tests/ceil_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from datetime import datetime

import polars as pl

import polars_xdt as xdt


Expand Down
5 changes: 3 additions & 2 deletions tests/julian_date_test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from __future__ import annotations

import datetime as dt

import hypothesis.strategies as st
import pandas as pd
import polars as pl
from hypothesis import given

import polars as pl
import pandas as pd
import polars_xdt as xdt


Expand Down
Loading

0 comments on commit df47882

Please sign in to comment.