Skip to main content

datespan

GitHub license PyPI version PyPI Downloads GitHub last commit unit tests build


A Python package for effortless date span parsing and management. Aimed for data analysis and processing, useful in any context requiring date & time spans.

pip install datespan
import pandas as pd
from datespan import parse, DateSpan
df = pd.DataFrame({"date": pd.date_range("2024-01-01", "2024-12-31")})

dss = parse("April 2024 ytd") # Create a DateSpanSet, same as 'DateSpanSet("April 2024 ytd")'
dss.add("May")                # Add full month May of the current year
dss.add("today")              # Add the current day from 00:00 to 23:59:59
dss += "previous week"        # Add a full week from Monday 00:00 to Sunday 23:59:59
dss -= "January"              # Remove full month January of the current year

print(len(dss))               # returns the number of contained nonconsecutive DateSpans
print(dss.to_tuples())        # returns a list of (start, end) tuples representing the DateSpanSet
print(dss.to_sql("date"))     # returns an SQL WHERE clause fragment
print(dss.filter(df, "date")) # returns a DataFrame filtered by the DateSpanSet on column 'date'

Classes

DateSpan represents a single date or time span, defined by a start and an end datetime. Provides methods to create, compare, merge, parse, split, shift, expand & intersect DateSpan objects and /or datetime, dateor time objects.

DateSpanSet represents an ordered and redundancy free collection of DateSpan objects, where consecutive or overlapping DateSpan objects get automatically merged into a single DateSpan object. Required for fragmented date span expressions like every 2nd Friday of next month.

DateSpanParser provides parsing for arbitrary date, time and date span strings in english language, ranging from simple dates like '2021-01-01' up to complex date span expressions like 'Mondays to Wednesday last month'. For internal DateTime parsing and manipulation, the DateUtil library is used.

Part of the CubedPandas Project

The 'dataspan' package has been carved out from the CubedPandas project, a library for easy, fast & fun data analysis with Pandas dataframes, as DataSpan serves a broader scope and purpose and can be used independently of CubedPandas.

Bugs, Issues, Feature Requests

Please report any bugs, issues, feature requests, questions or feedback on the GitHub Issues page. It will be highly appreciated and will help to improve the package.

Documentation

Documentation will be available from 0.3.0 release on.

Metadata

Release files for datespan 0.2.9

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

Source distribution (sdist)

Source distribution for datespan 0.2.9
File Size Uploaded Provenance Actions
datespan-0.2.9.tar.gz 42.4 kB Without provenance Details for datespan-0.2.9.tar.gz

Built distribution (wheel)

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

Total release size: 88.3 kB

Release files / datespan-0.2.9.tar.gz

Download URL datespan-0.2.9.tar.gz
Size 42.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ed3f532eefd792cd9301b1b90c3e7f15d622051258cb215d9f502327656c5ec3
BLAKE2b-256 checksum
How to use checksums
13b29f17bb1456093279fb9eb7c9ed0d156c930f7fde02ece9b5636bf94f14a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Release files / datespan-0.2.9-py3-none-any.whl

Download URL datespan-0.2.9-py3-none-any.whl
Size 45.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e616b1c0ef27cb8af95f48a1e78f9182fbd44275bf300433ca37239e9e155fbd
BLAKE2b-256 checksum
How to use checksums
d1410941ca59ca14c831c944c139d5c5cbbbd29e1938fb9740785bacff063bcd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Security for datespan 0.2.9

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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