Skip to main content

timevec

python versions package version Coverage

Functions to create time vectors

Description

Time has a periodic nature due to the rotation of the earth and the position of the sun. This affects human behavior in various ways.

  • Seasonality ... periodicity in a year (seasonal distinction)
  • Daily periodicity ... periodicity in a day (distinction between day and night)
  • Day of the week ... periodicity in a week (distinction between weekdays and holidays)

When dealing with these, it is desirable to vectorize with periodicity in mind. That is, at 23:59 on a given day, it is desirable that the value is close to 00:00 on the next day. To achieve this, the time is represented as a combination of cos and sin. This is called a time vector.

Installation

The base package has no NumPy dependency and supports timevec.builtin_math:

pip install timevec

Install the numpy extra when you use timevec.numpy or timevec.numpy_datetime64:

pip install "timevec[numpy]"

Usage

With the base install:

import datetime
import timevec.builtin_math as tv

dt = datetime.datetime(2020, 1, 1, 0, 0, 0)
vec = tv.year_vec(dt)
# (1.0, 0.0)

With the numpy extra:

import datetime
import timevec.numpy as tv

dt = datetime.datetime(2020, 1, 1, 0, 0, 0)
vec = tv.year_vec(dt)
# array([1., 0.])

Modules

  • timevec.numpy provides functions that return numpy.ndarray.
  • timevec.numpy_datetime64 provides functions that return numpy.datetime64.
  • timevec.builtin_math provides functions that return tuple of float.

Functions

Almost same functions are provided in timevec.numpy, timevec.numpy_datetime64, and timevec.builtin_math. The difference is the return type.

year_vec

year_vec(dt: datetime.datetime)

Create a time vector for a year. This is a vector that has periodicity like seasonality. (Summer, Autumn, Winter, Spring) year_vec

month_vec

month_vec(dt: datetime.datetime)

Create a time vector for a month. This is a vector that has periodicity in a month. You can express periodicity such as the beginning of the month, the end of the month, and the salary day. month_vec

week_vec

week_vec(dt: datetime.datetime)

Create a time vector for a week. This is a vector that has periodicity in a week. You can express periodicity such as weekdays and holidays. week_vec

day_vec

day_vec(dt: datetime.datetime)

Create a time vector for a day. This is a vector that has periodicity in a day. You can express periodicity such as morning, noon, and night. day_vec

Others

  • long_time_vec ... datetime.min to datetime.max period
  • millennium_vec ... one millennium (1000 years) period
  • century_vec ... one century (100 years) period
  • decade_vec ... one decade (10 years) period

Development

This repository uses lefthook to run the same checks as CI locally, so problems surface before they reach CI.

# Install dependencies
uv sync

# Install the Git hooks (once; requires lefthook on your PATH)
lefthook install

Once installed, the hooks run automatically:

  • pre-commit: uv run poe check
  • pre-push: uv run poe check and uv run poe test

You can also run the checks manually:

uv run poe check
uv run poe test

CI still runs the full matrix (see .github/workflows/); the hooks only bring that feedback earlier on your machine.

License

BSD 3-Clause License

Metadata

Release files for timevec 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for timevec 0.4.0
File Size Uploaded Provenance Actions
timevec-0.4.0.tar.gz 131.1 kB With provenance Details for timevec-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for timevec 0.4.0
File Interpreter ABI Platform Actions
timevec-0.4.0-py3-none-any.whl Python 3 none any Details for timevec-0.4.0-py3-none-any.whl

Total release size: 142.5 kB

Release files / timevec-0.4.0.tar.gz

Download URL timevec-0.4.0.tar.gz
Size 131.1 kB
Tags Source
SHA-256 checksum
How to use checksums
cf3c9b939d0f69b77d325f0794f53e95b0cefa9cf2e3d224a646e580df4b13b0
BLAKE2b-256 checksum
How to use checksums
a143bdad19400cec6e150d56cf86996f48764754c802597f625777cb893062da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

Release files / timevec-0.4.0-py3-none-any.whl

Download URL timevec-0.4.0-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cf9d8b128f6b2b66b76a34af7f1c456aa1094d8a3e070d1f6cceb579c0286f96
BLAKE2b-256 checksum
How to use checksums
accfbbaed02b14292d8c75570988d07c5e78e856505e01e1a1a2476aba890ccf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

Security for timevec 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for timevec-0.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page