Skip to content

Commit

Permalink
Merge pull request #326 from HLasse/pydantic-2
Browse files Browse the repository at this point in the history
feat: bump pydantic version to 2.0 and spacy version to >=3.6
  • Loading branch information
HLasse authored Apr 9, 2024
2 parents 5c7015a + 844c240 commit d900c46
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:

- name: Python Semantic Release
id: release
uses: python-semantic-release/python-semantic-release@v8.0.4
uses: python-semantic-release/python-semantic-release@v9.4.1
with:
github_token: ${{ secrets.RELEASE }}
root_options: "-vv"
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# e.g. links to wheels which is not allowed in pyproject.toml on pypi

# spacy pipeline
https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.4.0/en_core_web_sm-3.4.0.tar.gz
https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.6.0/en_core_web_sm-3.6.0.tar.gz
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ keywords = [
]

dependencies = [
"spacy[lookups]>=3.1.0",
"spacy[lookups]>=3.6.0",
"numpy>=1.20.0",
"pandas>=1.0.0",
"pyphen>=0.11.0,<0.15.0",
"ftfy>=6.0.3,<6.1.0",
"pydantic<2.0.0",
"pydantic>=2.0",
]

requires-python = ">=3.8"
Expand All @@ -53,13 +53,14 @@ documentation = "https://hlasse.github.io/TextDescriptives/"
style = ["black==24.1.1", "pre-commit==3.6.0", "ruff==0.1.15", "mypy==1.8.0"]
tests = ["pytest>=7.1.3", "pytest-cov>=3.0.0"]
docs = [
"pydantic==2.1",
"sphinx>=5.3.0",
"furo==2022.12.7",
"sphinx-copybutton>=0.5.1",
"sphinxext-opengraph>=0.7.3",
"myst-nb>=0.6.0",
"sphinx_design>=0.3.0",
"autodoc_pydantic==1.9.0",
"autodoc_pydantic==2.1.0",
]
tutorials = [
"jupyter",
Expand Down
2 changes: 1 addition & 1 deletion src/textdescriptives/components/quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ def set_quality(self, doc: Doc) -> None:
# to allow the variable to json serializable we convert it to json
# it is then converted back into a quality output object in the getter

doc._._quality = self.quality_setter(doc).dict()
doc._._quality = self.quality_setter(doc).model_dump()
doc._.passed_quality_check = self.passed_quality_thresholds(doc)

def passed_quality_thresholds(self, span: Union[Span, Doc]) -> bool:
Expand Down
11 changes: 4 additions & 7 deletions src/textdescriptives/components/quality_data_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import Any, Dict, Optional, Tuple, Union

from pydantic import BaseModel, Extra, Field
from pydantic import ConfigDict, BaseModel, Field

Interval = Tuple[Optional[float], Optional[float]]

Expand All @@ -21,8 +21,7 @@ class ThresholdsOutput(BaseModel):
True
"""

class Config:
extra = Extra.forbid
model_config = ConfigDict(extra="forbid")

threshold: Union[Interval, bool, None]
value: Union[float, None]
Expand Down Expand Up @@ -61,8 +60,7 @@ def __eq__(self, other: Any) -> bool:
class QualityThresholds(BaseModel):
"""Thresholds for quality metrics."""

class Config:
extra = Extra.forbid
model_config = ConfigDict(extra="forbid")

n_stop_words: Interval = Field(
(2, None),
Expand Down Expand Up @@ -164,8 +162,7 @@ class Config:
class QualityOutput(BaseModel):
"""The output of the quality function."""

class Config:
extra = Extra.forbid
model_config = ConfigDict(extra="forbid")

n_stop_words: ThresholdsOutput = Field(
...,
Expand Down
4 changes: 2 additions & 2 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# e.g. links to wheels which is not allowed in pyproject.toml on pypi

# spacy pipelines
https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.5.0/en_core_web_sm-3.5.0.tar.gz
https://github.com/explosion/spacy-models/releases/download/en_core_web_md-3.5.0/en_core_web_md-3.5.0.tar.gz
https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.6.0/en_core_web_sm-3.6.0.tar.gz
https://github.com/explosion/spacy-models/releases/download/en_core_web_md-3.6.0/en_core_web_md-3.6.0.tar.gz
3 changes: 1 addition & 2 deletions tests/test_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import pytest
import spacy

import textdescriptives as td
from textdescriptives.components.quality import (
alpha_ratio,
Expand Down Expand Up @@ -208,7 +207,7 @@ def test_quality_component_with_config(nlp: spacy.Language):
proportion_bullet_points=(None, 0.8),
duplicate_line_chr_fraction=(None, 0.2),
duplicate_paragraph_chr_fraction=(None, 0.2),
top_ngram_chr_fraction={2: (None, 0.6), 3: (None, 0.6)},
top_ngram_chr_fraction={"2": (None, 0.6), "3": (None, 0.6)},
duplicate_ngram_chr_fraction={},
contains={"lorem ipsum": False},
oov_ratio=(None, 0.3),
Expand Down

0 comments on commit d900c46

Please sign in to comment.