diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index e46401c..7945749 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -19,20 +19,21 @@ jobs: working-directory: . steps: - - uses: actions/checkout@v5 - + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Install uv - uses: astral-sh/setup-uv@v8.1.0 + uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0 with: python-version: "3.12" enable-cache: true - cache-dependency-glob: "pyproject.toml" + cache-dependency-glob: "uv.lock" - name: Install package with check dependencies run: uv sync --group check - name: Run Ruff linter - uses: astral-sh/ruff-action@v3 + uses: astral-sh/ruff-action@278981a28ce3188b1e39527901f38254bf3aac89b # v4.1.0 with: args: "check --output-format=github" @@ -48,7 +49,7 @@ jobs: # check types with mypy - name: Check types in python src directory; install needed types - run: uv run mypy --install-types --non-interactive src + run: uv run mypy --install-types --non-interactive src --follow-untyped-imports # use treon to make sure that example notebooks run - name: Check jupyter notebooks with treon diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 2a008cf..5aebffd 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -19,23 +19,20 @@ permissions: jobs: deploy: - runs-on: ubuntu-latest steps: - - uses: actions/checkout@v5 - - name: Set up Python - uses: actions/setup-python@v6 - with: - python-version: '3.x' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install build - - name: Build package - run: python -m build - - name: Publish package - uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 - with: - user: __token__ - password: ${{ secrets.PYPI_API_TOKEN }} + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Set up uv + uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0 + with: + python-version: "3.12" + - name: Build package + run: uv build + - name: Publish package + uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 806b68f..d0a1c31 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -13,8 +13,10 @@ on: branches: - "**" paths: - - 'undate/**' - - 'tests/**' + - "src/undate/**" + - "tests/**" + - "pyproject.toml" + - "uv.lock" pull_request: branches: - "**" @@ -28,21 +30,21 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python: ["3.10", "3.11", "3.12", "3.13"] + python: ["3.10", "3.11", "3.12", "3.13", "3.14"] defaults: run: working-directory: . steps: - - uses: actions/checkout@v5 - - # use github python action instead of uv to take advantage of caching + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Set up Python ${{ matrix.python }} - uses: astral-sh/setup-uv@v8.1.0 + uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0 with: python-version: ${{ matrix.python }} - cache: 'pip' - cache-dependency-path: '**/pyproject.toml' + enable-cache: true + cache-dependency-glob: "uv.lock" - name: Install package with check dependencies run: uv sync --group test @@ -58,8 +60,7 @@ jobs: if: ${{ matrix.python == env.COV_PYTHON_VERSION }} - name: Upload coverage to Codecov - uses: codecov/codecov-action@v5 + uses: codecov/codecov-action@0fb7174895f61a3b6b78fc075e0cd60383518dac # v5.5.5 env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} if: ${{ matrix.python == env.COV_PYTHON_VERSION }} - diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 873c6fd..475d234 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,13 +2,13 @@ files: \.py repos: # ruff for linting and formatting python - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.15.12 + rev: cb8c523fd4835aba42af70f4cad5568db4df0b6c # frozen: v0.16.0 hooks: - id: ruff-check - args: [ --fix, --show-fixes, --exit-non-zero-on-fix ] + args: [--fix, --show-fixes, --exit-non-zero-on-fix] - id: ruff-format - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v6.0.0 + rev: 3e8a8703264a2f4a69428a0aa4dcb512790b2c8c # frozen: v6.0.0 hooks: - id: check-case-conflict - id: check-merge-conflict @@ -22,18 +22,19 @@ repos: args: [--pytest-test-first] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v2.0.0 + rev: 41e691678310dfd3833f7ab4e180ddb014310356 # frozen: v2.3.0 hooks: - id: mypy additional_dependencies: [numpy] + # yamlfmt for formatting YAML files - repo: https://github.com/google/yamlfmt - rev: v0.21.0 + rev: b5ca1890231d5e1e5181fef75a1be609d1e25029 # frozen: v0.21.0 hooks: - id: yamlfmt # Codespell for spell checking - repo: https://github.com/codespell-project/codespell - rev: v2.4.2 + rev: 57b21406f092110c18776e39b0bda50d37c945c8 # frozen: v2.4.3 hooks: - id: codespell additional_dependencies: @@ -41,6 +42,6 @@ repos: exclude_types: ["css", "html", "javascript", "json"] # Validate GitHub Actions workflow files - repo: https://github.com/mpalmer/action-validator - rev: v0.9.0 + rev: 76a805bbfcba3506d6cdb4bba1810ab504e0d72b # frozen: v0.9.0 hooks: - id: action-validator diff --git a/CHANGELOG.md b/CHANGELOG.md index 1635a90..778fd00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Change Log +## 0.8 + +- ## 0.7 diff --git a/README.md b/README.md index 6eacf95..e35c2d0 100644 --- a/README.md +++ b/README.md @@ -7,20 +7,19 @@ > [!NOTE] > This is beta software; it is still in development and not fully feature complete. If you use it, please let us know and share your feedback. - Currently `undate` supports parsing, formatting, and reasoning with dates in varying precision and calendars; dates with different precision and from different original calendars can be used together. Supported formats include: -- portions of EDTF (Extended Date Time Format) -- ISO8601 -- parsing and calendar conversion for dates in Hebrew Anno Mundi and Islamic Hijri calendars -- Gregorian dates with full or abbreviated month names in any order for multiple languages (English, Spanish, French, German, Kinyarwanda, Ganda, Tigrinya) -- Christian liturgical dates (fixed holidays and movable feasts) + +- portions of **EDTF** (Extended Date Time Format) +- **ISO8601** +- parsing and calendar conversion for dates in **Hebrew Anno Mundi** and **Islamic Hijri** calendars +- **Gregorian** dates with full or abbreviated month names in any order for multiple languages (English, Spanish, French, German, Kinyarwanda, Ganda, Tigrinya) +- **Christian liturgical** dates (fixed holidays and movable feasts) For unambiguous dates, there is an experimental omnibus parser which combines all available dates (bare years are currently assumed to be Gregorian calendar). For more about the origin and goals of `undate`, read our 2025 software paper: -> Rebecca Sutton Koeser, Julia Damerow, Robert Casties, and Cole Crawford. “[Undate: Humanistic Dates for Computation](https://doi.org/10.1017/chr.2025.10006).” _Computational Humanities Research_, August 5, 2025. - +> Rebecca Sutton Koeser, Julia Damerow, Robert Casties, and Cole Crawford. "[Undate: Humanistic Dates for Computation](https://doi.org/10.1017/chr.2025.10006)." _Computational Humanities Research_, August 5, 2025. --- @@ -31,8 +30,6 @@ For more about the origin and goals of `undate`, read our 2025 software paper: [![codecov](https://codecov.io/gh/dh-tech/undate-python/branch/main/graph/badge.svg?token=GE7HZE8C9D)](https://codecov.io/gh/dh-tech/undate-python) [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) -Project documentation is [available on ReadTheDocs](https://undate-python.readthedocs.io/en/latest/). - [![All Contributors](https://img.shields.io/badge/all_contributors-5-orange.svg?style=flat-square)](CONTRIBUTORS.md) @@ -54,198 +51,26 @@ Use the `@name` notation to specify the branch or tag; e.g., to install developm pip install git+https://github.com/dh-tech/undate-python@develop#egg=undate ``` -## Example Usage - -Often humanities and cultural data include imprecise or uncertain -temporal information. We want to store that information but also work -with it in a structured way, not just treat it as text for display. -Different projects may need to work with or convert between different -date formats or even different calendars. +## Quick Start -An `undate.Undate` is analogous to python’s builtin `datetime.date` -object, but with support for varying degrees of precision and unknown -information. You can initialize an `Undate` with either strings or -numbers for whichever parts of the date are known or partially known. -An `Undate` can take an optional label. +An `Undate` is analogous to python’s `datetime.date` but supports varying degrees of precision and unknown information. Initialize with strings or numbers for whichever parts of the date are known: ```python -from undate import Undate +from undate import Undate, UndateInterval november7 = Undate(2000, 11, 7) november = Undate(2000, 11) year2k = Undate(2000) -november7_some_year = Undate(month=11, day=7) - partially_known_year = Undate("19XX") -partially_known_month = Undate(2022, "1X") - -easter1916 = Undate(1916, 4, 23, label="Easter 1916") -``` - -You can convert an `Undate` to string using a date formatter (current default is ISO8601): - -```python ->>> [str(d) for d in [november7, november, year2k, november7_some_year]] -['2000-11-07', '2000-11', '2000', '--11-07'] -``` - -If enough information is known, an `Undate` object can report on its duration: - -```python ->>> december = Undate(2000, 12) ->>> feb_leapyear = Undate(2024, 2) ->>> feb_regularyear = Undate(2023, 2) ->>> for d in [november7, november, december, year2k, november7_some_year, feb_regularyear, feb_leapyear]: -... print(f"{d} - duration in days: {d.duration().days}") -... -2000-11-07 - duration in days: 1 -2000-11 - duration in days: 30 -2000-12 - duration in days: 31 -2000 - duration in days: 366 ---11-07 - duration in days: 1 -2023-02 - duration in days: 28 -2024-02 - duration in days: 29 -``` - -If enough of the date is known and the precision supports it, you can -check if one date falls within another date: - -```python ->>> november7 = Undate(2000, 11, 7) ->>> november2000 = Undate(2000, 11) ->>> year2k = Undate(2000) ->>> ad100 = Undate(100) ->>> november7 in november -True ->>> november2000 in year2k -True ->>> november7 in year2k -True ->>> november2000 in ad100 -False ->>> november7 in ad100 -False -``` -For dates that are imprecise or partially known, `undate` calculates -earliest and latest possible dates for comparison purposes so you can -sort dates and compare with equals, greater than, and less than. You -can also compare with python `datetime.date` objects. - -```python ->>> november7_2020 = Undate(2020, 11, 7) ->>> november_2001 = Undate(2001, 11) ->>> year2k = Undate(2000) ->>> ad100 = Undate(100) ->>> sorted([november7_2020, november_2001, year2k, ad100]) -[undate.Undate(year=100, calendar="Gregorian"), undate.Undate(year=2000, calendar="Gregorian"), undate.Undate(year=2001, month=11, calendar="Gregorian"), undate.Undate(year=2020, month=11, day=7, calendar="Gregorian")] ->>> november7_2020 > november_2001 -True ->>> year2k < ad100 -False ->>> from datetime import date ->>> year2k > date(2001, 1, 1) -False -``` - -When dates cannot be compared due to ambiguity or precision, comparison -methods raise a `NotImplementedError`. - -```python ->>> november_2020 = Undate(2020, 11) ->>> november7_2020 > november_2020 -Traceback (most recent call last): - File "", line 1, in - File "/Users/rkoeser/workarea/github/undate-python/src/undate/undate.py", line 262, in __gt__ - return not (self < other or self == other) - File "/Users/rkoeser/workarea/github/undate-python/src/undate/undate.py", line 245, in __lt__ - raise NotImplementedError( -NotImplementedError: Can't compare when one date falls within the other -``` - -An `UndateInterval` is a date range between two `Undate` objects. -Intervals can be open-ended, allow for optional labels, and can -calculate duration if enough information is known. `UndateIntervals` -are inclusive (i.e., a closed interval), and include both the earliest -and latest date as part of the range. +print([str(d) for d in [november7, november, year2k, partially_known_year]]) +# [‘2000-11-07’, ‘2000-11’, ‘2000’, ‘19XX’] -```python ->>> from undate import UndateInterval ->>> UndateInterval(Undate(1900), Undate(2000)) -undate.UndateInterval(earliest=undate.Undate(year=1900, calendar="Gregorian"), latest=undate.Undate(year=2000, calendar="Gregorian")) ->>> UndateInterval(Undate(1801), Undate(1900), label="19th century") -undate.UndateInterval(earliest=undate.Undate(year=1801, calendar="Gregorian"), latest=undate.Undate(year=1900, calendar="Gregorian"), label="19th century") ->>> UndateInterval(Undate(1801), Undate(1900), label="19th century").duration().days -36524 ->>> UndateInterval(Undate(1901), Undate(2000), label="20th century") -undate.UndateInterval(earliest=undate.Undate(year=1901, calendar="Gregorian"), latest=undate.Undate(year=2000, calendar="Gregorian"), label="20th century") ->>> UndateInterval(latest=Undate(2000)) # before 2000 -undate.UndateInterval(latest=undate.Undate(year=2000, calendar="Gregorian")) ->>> UndateInterval(Undate(1900)) # after 1900 -undate.UndateInterval(earliest=undate.Undate(year=1900, calendar="Gregorian")) ->>> UndateInterval(Undate(1900), Undate(2000), label="19th century").duration().days -36890 ->>> UndateInterval(Undate(2000, 1, 1), Undate(2000, 1,31)).duration().days -31 -``` - -You can initialize `Undate` or `UndateInterval` objects by parsing a -date string with a specific converter, and you can also output an -`Undate` object in those formats. Currently available converters -are "ISO8601" and "EDTF" and supported calendars. - -```python ->>> from undate import Undate ->>> Undate.parse("2002", "ISO8601") -undate.Undate(year=2002, calendar="Gregorian") ->>> Undate.parse("2002-05", "EDTF") -undate.Undate(year=2002, month=5, calendar="Gregorian") ->>> Undate.parse("--05-03", "ISO8601") -undate.Undate(month=5, day=3, calendar="Gregorian") ->>> Undate.parse("--05-03", "ISO8601").format("EDTF") -'XXXX-05-03' ->>> Undate.parse("1800/1900", format="EDTF") -undate.UndateInterval(earliest=undate.Undate(year=1800, calendar="Gregorian"), latest=undate.Undate(year=1900, calendar="Gregorian")) +print(repr(Undate.parse("Rajab 495", "Islamic"))) +# undate.Undate(year=495, month=7, label="Rajab 495 Islamic", calendar="Islamic") ``` -### Calendars - -All `Undate` objects are calendar aware, and date converters include -support for parsing and working with dates from other calendars. The -Gregorian calendar is used by default; currently `undate` supports the -Islamic Hijri calendar and the Hebrew Anno Mundi calendar based on -calendar conversion logic implemented in the -[convertdate](https://convertdate.readthedocs.io/en/latest/) package. - -Dates are stored with the year, month, day and appropriate precision for -the original calendar; internally, earliest and latest dates are -calculated in Gregorian / Proleptic Gregorian calendar for standardized -comparison across dates from different calendars. - -```python ->>> from undate import Undate ->>> tammuz4816 = Undate.parse("26 Tammuz 4816", "Hebrew") ->>> tammuz4816 -undate.Undate(year=4816, month=4, day=26, label="26 Tammuz 4816 Anno Mundi", calendar="Hebrew") ->>> rajab495 = Undate.parse("Rajab 495", "Islamic") ->>> rajab495 -undate.Undate(year=495, month=7, label="Rajab 495 Islamic", calendar="Islamic") ->>> y2k = Undate.parse("2001", "EDTF") ->>> y2k -undate.Undate(year=2001, calendar="Gregorian") ->>> [str(d.earliest) for d in [rajab495, tammuz4816, y2k]] -['1102-04-28', '1056-07-17', '2001-01-01'] ->>> [str(d.precision) for d in [rajab495, tammuz4816, y2k]] -['MONTH', 'DAY', 'YEAR'] ->>> sorted([rajab495, tammuz4816, y2k]) -[undate.Undate(year=4816, month=4, day=26, label="26 Tammuz 4816 Anno Mundi", calendar="Hebrew"), undate.Undate(year=495, month=7, label="Rajab 495 Islamic", calendar="Islamic"), undate.Undate(year=2001, calendar="Gregorian")] -``` - ---- - -For more examples, refer to the code notebooks included in the -[examples](https://github.com/dh-tech/undate-python/tree/main/examples/) -directory in this repository. +For full examples including duration, comparison, intervals, parsing, and calendar support, see the [interactive documentation](https://undate-python.readthedocs.io/en/latest/). ## Documentation @@ -255,23 +80,21 @@ For instructions on setting up for local development, see [Developer Notes](DEVE See [Contributors](CONTRIBUTORS.md) for more detailed information about contributors. - ## Publications & Presentations -* Rebecca Sutton Koeser, Julia Damerow, Robert Casties, and Cole Crawford. “[Undate: Humanistic Dates for Computation](https://doi.org/10.1017/chr.2025.10006).” Software paper published in _Computational Humanities Research_, August 5, 2025. -* Rebecca Sutton Koeser. “[Undate: Computing with Uncertain and Partially-Unknown Dates](https://doi.org/10.5281/zenodo.17253974).” Computational notebook presented at USRSE’25. October 6, 2025. -* Rebecca Sutton Koeser. “[Undate in Action](https://rlskoeser.github.io/undate-in-action/).” Presentation at [Digital Humanities Tech Symposium](https://dh-tech.github.io/2025/06/04/digital-humanities-tech-symposium-agenda/), DH2025. July 14, 2025. -* Rebecca Sutton Koeser. 2025. “[Undate in Action](https://doi.org/10.63744/SFtXXpIE4ERh).” In Digital Humanities Tech Symposium 2025—Anthology of Computers and the Humanities, edited by Julia Damerow and Rebecca Sutton Koeser, vol. 2. -* Rebecca Sutton Koeser. [Join me for a DHTech hackathon? It’s an un-date!](https://dh-tech.github.io/blog/2023/02/09/hackathon-undate/) DHTech, February 9, 2023. +- Rebecca Sutton Koeser, Julia Damerow, Robert Casties, and Cole Crawford. “[Undate: Humanistic Dates for Computation](https://doi.org/10.1017/chr.2025.10006).” Software paper published in _Computational Humanities Research_, August 5, 2025. +- Rebecca Sutton Koeser. “[Undate: Computing with Uncertain and Partially-Unknown Dates](https://doi.org/10.5281/zenodo.17253974).” Computational notebook presented at USRSE’25. October 6, 2025. +- Rebecca Sutton Koeser. “[Undate in Action](https://rlskoeser.github.io/undate-in-action/).” Presentation at [Digital Humanities Tech Symposium](https://dh-tech.github.io/2025/06/04/digital-humanities-tech-symposium-agenda/), DH2025. July 14, 2025. +- Rebecca Sutton Koeser. 2025. “[Undate in Action](https://doi.org/10.63744/SFtXXpIE4ERh).” In Digital Humanities Tech Symposium 2025—Anthology of Computers and the Humanities, edited by Julia Damerow and Rebecca Sutton Koeser, vol. 2. +- Rebecca Sutton Koeser. [Join me for a DHTech hackathon? It’s an un-date!](https://dh-tech.github.io/blog/2023/02/09/hackathon-undate/) DHTech, February 9, 2023. ## Related Projects - ISO8601 date support and dates with unknown years, including duration, adapted from [Shakespeare and Company Project](https://shakespeareandco.princeton.edu/) ([codebase](https://github.com/Princeton-CDH/mep-django)) -- Parsing and calendar conversion for Hebrew Anno Mundi and Islamic Hijri calendars adapted from [Princeton Geniza Project (PGP)](https://geniza.princeton.edu/) ([codebase](https://github.com/Princeton-CDH/geniza/)); improved and verified with data and logic from the [Islamic Scientific Manuscripts Initiative (ISMI)](https://ismi.mpiwg-berlin.mpg.de/) +- Parsing and calendar conversion for Hebrew Anno Mundi and Islamic Hijri calendars adapted from [Princeton Geniza Project (PGP)](https://geniza.princeton.edu/) ([codebase](https://github.com/Princeton-CDH/geniza/)); improved and verified with data and logic from the [Islamic Scientific Manuscripts Initiative (ISMI)](https://ismi.mpiwg-berlin.mpg.de/) - Parsing for dates in African languages inspired by work on and partially checked against data from [MasakhaNER](https://github.com/masakhane-io/masakhane-ner) - Parsing and calendar conversion for Christian liturgical holidays adapted from work on [Hale/Eliot Letters project](https://cdh.princeton.edu/projects/haleeliot-letters/) - ## License This software is licensed under the [Apache 2.0 License](LICENSE.md). diff --git a/docs/_static/custom.css b/docs/_static/custom.css index aa35e82..6ba85cf 100644 --- a/docs/_static/custom.css +++ b/docs/_static/custom.css @@ -1,4 +1,9 @@ +.sidebar-logo { + width: 200px; + height: auto; +} + div.sphinxsidebar .powered_by a { text-decoration: none; border-bottom: none; diff --git a/docs/_static/undate_logo.svg b/docs/_static/undate_logo.svg new file mode 100644 index 0000000..52bba2e --- /dev/null +++ b/docs/_static/undate_logo.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/docs/_static/undate_logo_dark.svg b/docs/_static/undate_logo_dark.svg new file mode 100644 index 0000000..bc907b7 --- /dev/null +++ b/docs/_static/undate_logo_dark.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/docs/conf.py b/docs/conf.py index a55e3ae..29957ad 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -10,20 +10,21 @@ # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. # -# import os -# import sys -# sys.path.insert(0, os.path.abspath('.')) +import sys +from pathlib import Path + +sys.path.insert(0, str(Path.cwd())) import undate # -- Project information ----------------------------------------------------- project = "undate" -copyright = "2024, DHtech" +copyright = "2026, DHtech" author = "DHtech Community" # The full version, including alpha/beta/rc tags -release = undate.__version__ +release = undate.__version__ # type: ignore[attr-defined] master_doc = "index" @@ -37,8 +38,12 @@ "sphinx.ext.autodoc", "sphinx.ext.intersphinx", "myst_parser", + "sphinx_pyodide", ] +# build static output for noscript fallback +pyodide_build_output = True + # Add any paths that contain templates here, relative to this directory. templates_path = ["_templates"] @@ -57,30 +62,34 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -html_theme = "alabaster" +html_theme = "furo" # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ["_static"] +html_css_files = ["custom.css"] html_theme_options = { - "logo": "undate_logo.png", - "logo_name": False, - "github_user": "dh-tech", - "github_repo": "undate-python", - "github_button": False, - "github_banner": True, -} - -html_sidebars = { - "**": [ - "about.html", - "navigation.html", - "localtoc.html", - "searchbox.html", - "sidebar_dhtech.html", - ], + "light_logo": "undate_logo.svg", + "dark_logo": "undate_logo_dark.svg", + "source_repository": "https://github.com/dh-tech/undate-python", + "source_branch": "main", + "source_directory": "docs/", + "light_css_variables": { + "color-brand-primary": "#6670bb", + "color-brand-content": "#6670bb", + "color-background-primary": "#f0f1f8", + "color-background-secondary": "#e5e7f2", + "sidebar-logo-width": "200px", + }, + "dark_css_variables": { + "color-brand-primary": "#9198d0", + "color-brand-content": "#9198d0", + "color-background-primary": "#1d202f", + "color-background-secondary": "#151825", + "sidebar-logo-width": "200px", + }, } # turn on relative links; make sure both github and sphinx links work diff --git a/docs/example_usage.rst b/docs/example_usage.rst new file mode 100644 index 0000000..c6c501b --- /dev/null +++ b/docs/example_usage.rst @@ -0,0 +1,232 @@ +Example Usage +-------------- + +Often humanities and cultural data include imprecise or uncertain temporal information. We want to store that information but also work with it in a structured way, not just treat it as text for display. Different projects may need to work with or convert between different date formats or even different calendars. + +An ``undate.Undate`` is analogous to python’s builtin ``datetime.date`` object, but with support for varying degrees of precision and unknown information. You can initialize an ``Undate`` with either strings or numbers for whichever parts of the date are known or partially known. An ``Undate`` can take an optional label. + +.. pyodide:: + :packages: ./wheels/PyMeeus-0.5.12-py3-none-any.whl,./wheels/undate-0.8.0.dev0-py3-none-any.whl + + from undate import __version__ + + print(f"Running undate v{__version__}") + + +.. pyodide:: + from undate import Undate + + november7 = Undate(2000, 11, 7) + november = Undate(2000, 11) + year2k = Undate(2000) + november7_some_year = Undate(month=11, day=7) + + partially_known_year = Undate("19XX") + partially_known_month = Undate(2022, "1X") + + easter1916 = Undate(1916, 4, 23, label="Easter 1916") + +You can convert an ``Undate`` to string using a date formatter (current default is ISO8601): + + +.. pyodide:: + print([str(d) for d in [november7, november, year2k, november7_some_year]]) + + +If enough information is known, an ``Undate`` object can report on its duration: + +.. pyodide:: + december = Undate(2000, 12) + feb_leapyear = Undate(2024, 2) + feb_regularyear = Undate(2023, 2) + + example_dates = [ + november7, november, december, year2k, + november7_some_year, feb_regularyear, feb_leapyear + ] + for d in example_dates: + print(f"{d!s:<10} duration in days: {d.duration().days:>2}") + +If enough of the date is known and the precision supports it, you can +check if one date falls within another date: + +.. pyodide:: + november7 = Undate(2000, 11, 7) + november2000 = Undate(2000, 11) + year2k = Undate(2000) + ad100 = Undate(100) + november7 in november + + yes_no = {True: "✅", False: "❌"} + for range in [november2000, year2k, ad100]: + print(f"{november7!s:>10} within {range!s:<10}? {yes_no[november7 in range]}") + if november2000 != range: # don't test against itself + print(f"{november2000!s:>10} within {range!s:<10}? {yes_no[november2000 in range]}") + + +For dates that are imprecise or partially known, ``undate`` calculates +earliest and latest possible dates for comparison purposes so you can +sort dates ... + +.. pyodide:: + november7_2020 = Undate(2020, 11, 7) + november_2001 = Undate(2001, 11) + year2k = Undate(2000) + ad100 = Undate(100) + for date in sorted([november7_2020, november_2001, year2k, ad100]): + # print the date in ISO/EDTF format along with the python representation + print(f"{date!s:>10} : {repr(date)}") + + +You can also compare with equals, greater than, and less than. You +can also compare with python ``datetime.date`` objects. + +.. pyodide:: + from datetime import date + + jan2001 = date(2001, 1, 1) + + print(f"{november7_2020!s:>10} before {november_2001!s:<10} ? {yes_no[november7_2020 < november_2001]}") + print(f"{year2k!s:>10} after {ad100!s:<10} ? {yes_no[year2k > ad100]}") + print(f"{year2k!s:>10} after {jan2001} ? {yes_no[year2k > jan2001]}") + + +When dates cannot be compared due to ambiguity or precision, comparison +methods raise a ``NotImplementedError``. + +.. pyodide:: + :show-errors: + + november_2020 = Undate(2020, 11) + try: + november7_2020 > november_2020 + except NotImplementedError as err: + print(err) + +An ``UndateInterval`` is a date range between two ``Undate`` objects. +Intervals can be open-ended, allow for optional labels, and can +calculate duration if enough information is known. ``UndateIntervals`` +are inclusive (i.e., a closed interval), and include both the earliest +and latest date as part of the range. + +.. pyodide:: + from undate import UndateInterval + + century19 = UndateInterval(Undate(1801), Undate(1900), label="19th century") + century20 = UndateInterval(Undate(1901), Undate(2000), label="20th century") + before2000 = UndateInterval(latest=Undate(1999)) # before 2000 + after1900 = UndateInterval(Undate(1901)) # after 1900 + + for interval in [century19, century20, before2000, after1900]: + print(f"{repr(interval)}\n{interval}\n") + +Intervals can calculate duration if enough information is known: + +.. pyodide:: + jan2000_interval = UndateInterval( + Undate(2000, 1, 1), + Undate(2000, 1, 31), + label="January 2000" + ) + for interval in [century19, century20, jan2000_interval]: + print(f"{interval.label}: {interval.duration().days:,} days") + +Parsing and Formatting +~~~~~~~~~~~~~~~~~~~~~~ + +You can initialize ``Undate`` or ``UndateInterval`` objects by parsing a +date string with a named converter, and output an ``Undate`` in a +different format than it was parsed. The ``"ISO8601"`` and ``"EDTF"`` +converters handle the most common structured formats: + +.. pyodide:: + print(repr(Undate.parse("2002", "ISO8601"))) + print(repr(Undate.parse("2002-05", "EDTF"))) + print(repr(Undate.parse("--05-03", "ISO8601"))) + print(repr(Undate.parse("1800/1900", "EDTF"))) + + # convert between formats + print(Undate.parse("--05-03", "ISO8601").format("EDTF")) + +The ``"Gregorian"`` converter parses dates with full or abbreviated month +names across multiple languages: + +.. pyodide:: + :editable: + :show-errors: + + dates = [ + "7 November 2000", + "Nov 2000", + "avril 1362", + "2022 Ugushyingo 26", + ] + for date in dates: + print(repr(Undate.parse(date, "Gregorian"))) + + +The ``"holidays"`` converter parses Christian liturgical dates, including +movable feasts: + +.. pyodide:: + :editable: + :show-errors: + + holidays = [ + "Epiphany 1942", + "Easter 1942", + "Ash Wednesday 1942", + ] + undate_holidays = [Undate.parse(hol, "holidays") for hol in holidays] + + for holidate in undate_holidays: + print(f"{holidate.label}: {holidate!s} (earliest: {holidate.earliest}, latest: {holidate.latest})") + + +Calendars +~~~~~~~~~ + +All ``Undate`` objects are calendar aware, and date converters include +support for parsing and working with dates from other calendars. The +Gregorian calendar is used by default; currently ``undate`` supports the +Islamic Hijri calendar and the Hebrew Anno Mundi calendar. + +Dates are stored with the year, month, day and appropriate precision for +the original calendar; internally, earliest and latest dates are +calculated in Gregorian / Proleptic Gregorian calendar for standardized +comparison across dates from different calendars. + +.. pyodide:: + tammuz4816 = Undate.parse("26 Tammuz 4816", "Hebrew") + rajab495 = Undate.parse("Rajab 495", "Islamic") + y2k1 = Undate.parse("2001", "EDTF") + + for d in [tammuz4816, rajab495, y2k1]: + print(f"{d!s:<10} {repr(d)}") + +.. pyodide:: + print("Earliest Gregorian equivalent:") + for d in [rajab495, tammuz4816, y2k1]: + print(f" {str(d):<20} earliest: {d.earliest}") + + print("\nPrecision:") + for d in [rajab495, tammuz4816, y2k1]: + print(f" {str(d):<20} precision: {d.precision}") + +.. pyodide:: + print("Sorted by Gregorian date:") + for d in sorted([rajab495, tammuz4816, y2k1]): + print(f" {repr(d)}") + +Try it yourself +~~~~~~~~~~~~~~~ + +.. pyodide:: + :editable: + :show-errors: + + # try your own dates here + from undate import Undate, UndateInterval + + mydate = Undate(2025, 6) + print(mydate) diff --git a/docs/index.rst b/docs/index.rst index 4f302f9..294c40d 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,14 +1,92 @@ -undate documentation -==================== +undate +====== -**undate** is a python library for working with uncertain or partially known dates. +.. image:: _static/undate_logo.svg + :alt: undate + :width: 350px + :class: only-light +.. image:: _static/undate_logo_dark.svg + :alt: undate + :width: 350px + :class: only-dark + +**undate** is a Python library for working with uncertain or partially known dates. + +.. image:: https://zenodo.org/badge/DOI/10.5281/zenodo.11068867.svg + :target: https://doi.org/10.5281/zenodo.11068867 +.. image:: https://img.shields.io/badge/License-Apache_2.0-blue.svg + :target: https://opensource.org/licenses/Apache-2.0 +.. image:: https://readthedocs.org/projects/undate-python/badge/?version=latest + :target: https://undate-python.readthedocs.io/en/latest/?badge=latest +.. image:: https://github.com/dh-tech/undate-python/actions/workflows/unit_tests.yml/badge.svg + :target: https://github.com/dh-tech/undate-python/actions/workflows/unit_tests.yml +.. image:: https://codecov.io/gh/dh-tech/undate-python/branch/main/graph/badge.svg?token=GE7HZE8C9D + :target: https://codecov.io/gh/dh-tech/undate-python + +.. note:: + This is beta software; it is still in development and not fully feature complete. + If you use it, please let us know and share your feedback. + +``undate`` supports parsing, formatting, and reasoning with dates in varying +precision and calendars. Dates with different precision and from different original +calendars can be used together. Supported formats include: + +- portions of EDTF (Extended Date Time Format) +- ISO8601 +- parsing and calendar conversion for dates in Hebrew Anno Mundi and Islamic Hijri calendars +- Gregorian dates with full or abbreviated month names in any order for multiple languages + (English, Spanish, French, German, Kinyarwanda, Ganda, Tigrinya) +- Christian liturgical dates (fixed holidays and movable feasts) + +For unambiguous dates, there is an experimental omnibus parser which combines all available parsers. + +For more about the origin and goals of ``undate``, read our 2025 software paper: + + Rebecca Sutton Koeser, Julia Damerow, Robert Casties, and Cole Crawford. + "`Undate: Humanistic Dates for Computation `_." + *Computational Humanities Research*, August 5, 2025. + +Quick Start +----------- + +An ``Undate`` is analogous to Python's ``datetime.date``, but with support for +varying precision and unknown information: + +.. code-block:: python + + from undate import Undate, UndateInterval + + november = Undate(2000, 11) # year and month known + year2k = Undate(2000) # year only + partially_known = Undate("19XX") # partially unknown year + + print([str(d) for d in [november, year2k, partially_known]]) + # ['2000-11', '2000', '19XX'] + +Dates can be parsed from multiple formats and calendars, sorted, and compared +even when precision differs. See :doc:`example_usage` for interactive examples. + +Installation +------------ + +Install the latest published version from PyPI: + +.. code-block:: console + + pip install undate + +To install a development version or specific branch: + +.. code-block:: console + + pip install git+https://github.com/dh-tech/undate-python@develop#egg=undate .. toctree:: - :maxdepth: 2 + :maxdepth: 1 :caption: Contents: - readme + example_usage undate/index CONTRIBUTING DEVELOPER_NOTES diff --git a/docs/readme.md b/docs/readme.md deleted file mode 100644 index 4ec94a5..0000000 --- a/docs/readme.md +++ /dev/null @@ -1,4 +0,0 @@ -```{include} ../README.md -:relative-docs: / -:relative-images: -``` diff --git a/examples/pgp_dates.ipynb b/examples/pgp_dates.ipynb index 65ece5e..f3819aa 100644 --- a/examples/pgp_dates.ipynb +++ b/examples/pgp_dates.ipynb @@ -1065,7 +1065,7 @@ " \"night, \",\n", " ]\n", " for mod in modifiers:\n", - " value = re.sub(mod, \"\", value, flags=re.I)\n", + " value = re.sub(mod, \"\", value, flags=re.IGNORECASE)\n", "\n", " # there are a handful of misspelled wednesdays...\n", " value = value.replace(\"Wedensday\", \"Wednesday\")\n", @@ -1073,10 +1073,9 @@ " value = value.replace(\"Thrusday\", \"Thursday\")\n", "\n", " # three Hebrew calendar dates include text \"AM\" at end; at least one AH date\n", - " if value.endswith(\" AM\") or value.endswith(\" AH\"):\n", + " if value.endswith((\" AM\", \" AH\")):\n", " value = value[:-3]\n", - " if value.endswith(\".\"): # strip off trailing period\n", - " value = value[:-1]\n", + " value = value.removesuffix(\".\")\n", "\n", " # about 62 have ordinals; strip them out\n", " value = remove_ordinals(value)\n", diff --git a/pyproject.toml b/pyproject.toml index 09c8ca5..3a05fa2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,6 +40,7 @@ classifiers = [ "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3.14", "Intended Audience :: Developers", "Intended Audience :: Science/Research", "Operating System :: OS Independent", @@ -51,7 +52,13 @@ classifiers = [ ] [dependency-groups] -docs = ["sphinx>=7.0.0", "alabaster", "myst-parser", "myst-parser[linkify]"] +docs = [ + "sphinx>=8.0.0", + "furo", + "myst-parser", + "myst-parser[linkify]", + "sphinx-pyodide", +] test = ["pytest>=9", "pytest-ordering", "pytest-cov"] notebooks = ["jupyterlab", "pandas", "treon", "altair"] check = [ { include-group = "docs" }, {include-group = "notebooks"}, "mypy", "ruff"] @@ -60,9 +67,10 @@ dev = [ "twine", "wheel", "build", + "sphinx-autobuild>=2024.10.3", { include-group = "test" }, { include-group = "check" }, - { include-group = "docs" } + { include-group = "docs" }, ] [project.urls] @@ -122,3 +130,7 @@ ignore = [] [tool.ruff.lint.per-file-ignores] # for test files, don't require docstrings or return type annotations "tests/**.py" = ["D", "ANN", "RUF"] + +# uncomment for local development of sphinx-pyodide +#[tool.uv.sources] +#sphinx-pyodide = { path = "../sphinx-pyodide", editable = true } diff --git a/scripts/generate_gregorian_grammar.py b/scripts/generate_gregorian_grammar.py old mode 100644 new mode 100755 diff --git a/src/undate/__init__.py b/src/undate/__init__.py index 06082fe..5b91527 100644 --- a/src/undate/__init__.py +++ b/src/undate/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.7.0" +__version__ = "0.8.0.dev0" # this sort order is important to avoid circular imports diff --git a/src/undate/converters/base.py b/src/undate/converters/base.py index 3845311..33c8308 100644 --- a/src/undate/converters/base.py +++ b/src/undate/converters/base.py @@ -121,7 +121,7 @@ def available_converters(cls) -> dict[str, type["BaseDateConverter"]]: """ Dictionary of available converters keyed on name. """ - return {c.name: c for c in cls.subclasses()} # type: ignore + return {c.name: c for c in cls.subclasses()} @classmethod def subclasses(cls) -> set[type["BaseDateConverter"]]: @@ -158,9 +158,9 @@ class BaseCalendarConverter(BaseDateConverter): LEAP_YEAR: int # minimum year for this calendar, if there is one - MIN_YEAR: None | int = None + MIN_YEAR: int | None = None # maximum year for this calendar, if there is one - MAX_YEAR: None | int = None + MAX_YEAR: int | None = None def min_month(self) -> int: """Smallest numeric month for this calendar.""" @@ -195,7 +195,7 @@ def days_in_year(self, year: int) -> int: # add 1 because the difference doesn't include the end point return (year_end - year_start).days + 1 - def representative_years(self, years: None | list[int] = None) -> list[int]: + def representative_years(self, years: list[int] | None = None) -> list[int]: """Returns a list of representative years within the specified list. Result should include one for each type of variant year for this calendar (e.g., leap year and non-leap year). If no years are specified, diff --git a/src/undate/converters/calendars/gregorian/converter.py b/src/undate/converters/calendars/gregorian/converter.py index 31bf05d..8effedf 100644 --- a/src/undate/converters/calendars/gregorian/converter.py +++ b/src/undate/converters/calendars/gregorian/converter.py @@ -53,7 +53,7 @@ def max_day(self, year: int, month: int) -> int: return max_day - def representative_years(self, years: None | list[int] = None) -> list[int]: + def representative_years(self, years: list[int] | None = None) -> list[int]: """Takes a list of years and returns a subset with one leap year and one non-leap year. If no years are specified, returns a known leap year and non-leap year. """ diff --git a/src/undate/converters/calendars/hebrew/converter.py b/src/undate/converters/calendars/hebrew/converter.py index 901c8a3..5735311 100644 --- a/src/undate/converters/calendars/hebrew/converter.py +++ b/src/undate/converters/calendars/hebrew/converter.py @@ -1,4 +1,4 @@ -from convertdate import hebrew # type: ignore +from convertdate import hebrew from lark.exceptions import UnexpectedInput from undate import Undate, UndateInterval @@ -59,7 +59,7 @@ def days_in_year(self, year: int) -> int: """the number of days in the specified year for this calendar""" return int(hebrew.year_days(year)) - def representative_years(self, years: None | list[int] = None) -> list[int]: + def representative_years(self, years: list[int] | None = None) -> list[int]: """Takes a list of years and returns a subset with all possible variations in number of days. If no years are specified, returns ... """ diff --git a/src/undate/converters/calendars/islamic/converter.py b/src/undate/converters/calendars/islamic/converter.py index f0962fc..ad77e6c 100644 --- a/src/undate/converters/calendars/islamic/converter.py +++ b/src/undate/converters/calendars/islamic/converter.py @@ -1,4 +1,4 @@ -from convertdate import islamic # type: ignore +from convertdate import islamic from lark.exceptions import UnexpectedInput from undate import Undate, UndateInterval @@ -25,7 +25,7 @@ class IslamicDateConverter(BaseCalendarConverter): LEAP_YEAR: int = 1458 # minimum year for islamic calendar is 1 AH, does not go negative - MIN_YEAR: None | int = 1 + MIN_YEAR: int | None = 1 # convertdate gives a month 34 for numpy max year 2.5^16, so scale it back a bit MAX_YEAR = int(2.5e12) @@ -44,7 +44,7 @@ def max_month(self, year: int) -> int: """maximum numeric month for this calendar""" return 12 - def representative_years(self, years: None | list[int] = None) -> list[int]: + def representative_years(self, years: list[int] | None = None) -> list[int]: """Takes a list of years and returns a subset with one leap year and one non-leap year. If no years are specified, returns a known leap year and non-leap year. """ diff --git a/src/undate/date.py b/src/undate/date.py index 9ef3da3..706a7fe 100644 --- a/src/undate/date.py +++ b/src/undate/date.py @@ -1,5 +1,5 @@ import operator -from collections.abc import Iterable +from collections.abc import Iterator from dataclasses import dataclass, replace from enum import IntEnum @@ -49,7 +49,7 @@ def __post_init__(self): f"Lower value ({self.lower}) must be less than upper ({self.upper})" ) - def __iter__(self) -> Iterable: + def __iter__(self) -> Iterator: # yield all integers in range from lower to upper, inclusive yield from range(self.lower, self.upper + 1) diff --git a/src/undate/interval.py b/src/undate/interval.py index 774cc89..8a88274 100644 --- a/src/undate/interval.py +++ b/src/undate/interval.py @@ -145,9 +145,9 @@ def __contains__(self, other: object) -> bool: try: other = Undate.to_undate(other) other_latest = other_earliest = other - except TypeError: + except TypeError as err: # if conversion fails, then we don't support comparison - raise + raise TypeError(f"Comparison not supported with {other}") from err # if either bound of the current interval is None, # then it is an open interval and we don't need to check the other value. diff --git a/src/undate/undate.py b/src/undate/undate.py index 7128084..30f5dc2 100644 --- a/src/undate/undate.py +++ b/src/undate/undate.py @@ -40,7 +40,7 @@ def get_converter(calendar) -> BaseCalendarConverter: except KeyError as err: raise ValueError(f"Unknown calendar '{calendar}'") from err if not issubclass(converter_cls, BaseCalendarConverter): - raise ValueError( + raise TypeError( f"Requested converter '{calendar.value.title()}' is not a CalendarConverter" ) return converter_cls() diff --git a/tests/test_date.py b/tests/test_date.py index e0eb5d7..3406d08 100644 --- a/tests/test_date.py +++ b/tests/test_date.py @@ -252,7 +252,7 @@ def test_eq(self): # not equal to equivalent undelta range assert udelt1 != udelt2 # equal to self - assert udelt1 is udelt1 + assert udelt1 is udelt1 # noqa: PLR0124 def test_lt(self): week_or_tenday = UnDelta(7, 10) diff --git a/tests/test_interval.py b/tests/test_interval.py index 828833c..9c97464 100644 --- a/tests/test_interval.py +++ b/tests/test_interval.py @@ -210,7 +210,7 @@ def test_contains(self): decade1990s = UndateInterval(Undate(1990), Undate(1999)) # an interval DOES contain itself for interval in [century11th, century20th, decade1990s]: - assert interval in interval + assert interval in interval # noqa: PLR0124 # checking if an interval is within another interval assert decade1990s in century20th @@ -252,4 +252,4 @@ def test_contains(self): assert decade1990s in whenever # NOTE: an interval contains itself or an equivalent interval, # but that may not make sense for open intervals... - assert whenever in whenever + assert whenever in whenever # noqa: PLR0124 diff --git a/tests/test_undate.py b/tests/test_undate.py index 3d65667..7725af9 100644 --- a/tests/test_undate.py +++ b/tests/test_undate.py @@ -1,4 +1,4 @@ -from datetime import date, datetime +import datetime from enum import auto from unittest import mock @@ -180,11 +180,11 @@ def test_invalid_date(self): Undate(1990, 22) def test_to_undate(self): - undate_from_date = Undate.to_undate(date(2001, 3, 5)) + undate_from_date = Undate.to_undate(datetime.date(2001, 3, 5)) assert isinstance(undate_from_date, Undate) assert undate_from_date == Undate(2001, 3, 5) - now = datetime.now() + now = datetime.datetime.now(tz=datetime.timezone.utc) undate_from_dt = Undate.to_undate(now) assert isinstance(undate_from_dt, Undate) assert undate_from_dt == Undate(now.year, now.month, now.day) @@ -266,13 +266,13 @@ def test_eq(self): def test_eq_datetime_date(self): # support comparisons with datetime objects for full day-precision - assert Undate(2022, 10, 1) == date(2022, 10, 1) - assert Undate(2022, 10, 1) != date(2022, 10, 2) - assert Undate(1980, 10, 1) != date(2022, 10, 1) + assert Undate(2022, 10, 1) == datetime.date(2022, 10, 1) + assert Undate(2022, 10, 1) != datetime.date(2022, 10, 2) + assert Undate(1980, 10, 1) != datetime.date(2022, 10, 1) # other date precisions are not equal - assert Undate(2022) != date(2022, 10, 1) - assert Undate(2022, 10) != date(2022, 10, 1) + assert Undate(2022) != datetime.date(2022, 10, 1) + assert Undate(2022, 10) != datetime.date(2022, 10, 1) def test_not_eq(self): assert Undate(2022) != Undate(2023) @@ -301,8 +301,8 @@ def test_not_eq(self): (Undate("19XX"), Undate("20XX")), (Undate(1900, "0X"), Undate(1900, "1X")), # compare with datetime.date objects - (Undate("19XX"), date(2020, 1, 1)), - (Undate(1991, 1), date(1992, 3, 4)), + (Undate("19XX"), datetime.date(2020, 1, 1)), + (Undate(1991, 1), datetime.date(1992, 3, 4)), ] @pytest.mark.parametrize("earlier,later", testdata_lt_gt) @@ -318,7 +318,7 @@ def test_lt(self, earlier, later): (Undate(1991, 1), Undate(1991, 1)), (Undate(1492, 5, 3), Undate(1492, 5, 3)), # compare with datetime.date also - (Undate(1492, 5, 3), date(1492, 5, 3)), + (Undate(1492, 5, 3), datetime.date(1492, 5, 3)), ] ) @@ -327,8 +327,8 @@ def test_lt_when_eq(self): assert not Undate(1900) > Undate(1900) assert not Undate(1900) < Undate(1900) # same for datetime.date - assert not Undate(1903, 1, 5) < date(1903, 1, 5) - assert not Undate(1903, 1, 5) > date(1903, 1, 5) + assert not Undate(1903, 1, 5) < datetime.date(1903, 1, 5) + assert not Undate(1903, 1, 5) > datetime.date(1903, 1, 5) @pytest.mark.parametrize("earlier,later", testdata_lte_gte) def test_lte(self, earlier, later): @@ -376,8 +376,8 @@ def test_lt_notimplemented(self): (Undate(2022, 12, 31), Undate(2022)), (Undate(2022, 6, 15), Undate(2022, 6)), # support contains with datetime.date - (date(2022, 6, 1), Undate(2022)), - (date(2022, 6, 1), Undate(2022, 6)), + (datetime.date(2022, 6, 1), Undate(2022)), + (datetime.date(2022, 6, 1), Undate(2022, 6)), ] @pytest.mark.parametrize("date1,date2", testdata_contains) @@ -393,8 +393,8 @@ def test_contains(self, date1, date2): (Undate(1980), Undate(2020, 6)), (Undate(1980, 6), Undate(2020, 6)), # support contains with datetime.date - (date(1980, 6, 1), Undate(2022)), - (date(3001, 6, 1), Undate(2022, 6)), + (datetime.date(1980, 6, 1), Undate(2022)), + (datetime.date(3001, 6, 1), Undate(2022, 6)), # partially known dates that are similar but same precision, # so one does not contain the other (Undate("199X"), Undate("19XX")), @@ -684,6 +684,6 @@ class DummyFormatter(BaseDateConverter): # NOTE: this fails because get_converter converts the enum to title case... # can't be tested with any of the existing non-calendar converters with pytest.raises( - ValueError, match="Requested converter 'Dummy' is not a CalendarConverter" + TypeError, match="Requested converter 'Dummy' is not a CalendarConverter" ): Calendar.get_converter(BogusCalendar.DUMMY)