Skip to main content

Effortless date span parsing and management.

Project description

datespan - effortless date span parsing and management

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 object
dss.add("May")                # Add a full month of the current year (e.g. 2024 in 2024)
dss.add("today")              # Add the current day from 00:00:00 to 23:59:59
dss += "previous week"        # Add a full week from Monday 00:00:00 to Sunday 23:59
dss -= "January"              # Remove the full month of January 2024

print(len(dss))               # returns the number of nonconsecutive DateSpans
print(dss.to_sql("date"))     # returns an SQL WHERE clause fragment
print(dss.filter(df, "date")) # returns the DataFrame filtered by 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

datespan-0.2.5.tar.gz (41.3 kB view details)

Uploaded Source

Built Distribution

datespan-0.2.5-py3-none-any.whl (45.1 kB view details)

Uploaded Python 3

File details

Details for the file datespan-0.2.5.tar.gz.

File metadata

  • Download URL: datespan-0.2.5.tar.gz
  • Upload date:
  • Size: 41.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.0

File hashes

Hashes for datespan-0.2.5.tar.gz
Algorithm Hash digest
SHA256 15dca192b18d406a6c0b4d6916aa4e730b00aa0bae272e1d4e62dcb0ff9b93ca
MD5 0b87088660f321ff04dd0a04cfdb8fea
BLAKE2b-256 abb0ae5b5350dafc55470a3ea6ee0444c50d698cdd6f7f70b3699413f7754b99

See more details on using hashes here.

File details

Details for the file datespan-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: datespan-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 45.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.0

File hashes

Hashes for datespan-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a0260c48a173ff0d2ac3f765bac856fa0a4aea66f4cfef619788a3076ea83dad
MD5 86de6013e496ffa8474bee337382bb0b
BLAKE2b-256 7217b2179b4051a48c8e37bf9f8b8b0a0b06cb7d3285965485569b1e3cf1b4f5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page