Skip to content

Commit dd55609

Browse files
authored
Merge pull request #51 from olp-cs/upgrade-to-pydantic-v2
Upgrade to Pydantic 2.8.2
2 parents efba432 + 43043d2 commit dd55609

13 files changed

+50
-55
lines changed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ classifiers=[
3636
# core dependencies of harmony
3737
# this set should be kept minimal!
3838
dependencies = [
39-
"pydantic==1.10.7; python_version <= '3.12'",
39+
"pydantic==2.8.2; python_version <= '3.12'",
4040
"pandas==2.0.0; python_version <= '3.12'",
4141
"tika==2.6.0; python_version <= '3.12'",
4242
"lxml==4.9.2; python_version <= '3.12'",

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pydantic==1.10.7
1+
pydantic==2.8.2
22
pandas==2.0.0
33
tika==2.6.0
44
lxml==4.9.2

src/harmony/examples.py

+1-1
Large diffs are not rendered by default.

src/harmony/matching/matcher.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def match_instruments_with_function(
208208
ctrs[all_questions[idx].instrument_id] = Counter()
209209
for topic in mhc_all_metadatas[mhc_item_idx]["topics"]:
210210
ctrs[all_questions[idx].instrument_id][topic] += 1
211-
all_questions[idx].nearest_match_from_mhc_auto = mhc_questions[mhc_item_idx].dict()
211+
all_questions[idx].nearest_match_from_mhc_auto = mhc_questions[mhc_item_idx].model_dump()
212212
strength_of_match = similarities_mhc[idx, mhc_item_idx]
213213
all_questions[idx].topics_strengths = {topic: float(strength_of_match)}
214214

src/harmony/schemas/requests/text.py

+34-39
Large diffs are not rendered by default.

src/harmony/schemas/responses/text.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
from harmony.schemas.requests.text import Instrument
3131
from harmony.schemas.requests.text import Question
32-
from pydantic import BaseModel, Field
32+
from pydantic import BaseModel, Field, RootModel
3333

3434

3535
class MatchResponse(BaseModel):
@@ -42,8 +42,8 @@ class MatchResponse(BaseModel):
4242
)
4343

4444

45-
class InstrumentList(BaseModel):
46-
__root__: List[Instrument]
45+
class InstrumentList(RootModel):
46+
root: List[Instrument]
4747

4848

4949
class CacheResponse(BaseModel):

src/harmony/util/instrument_helper.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def import_instrument_into_harmony_web(instrument: Instrument, harmony_fe_base_u
5252
@param harmony_fe_base_url: The base URL of the React app front end, defaulting to the web Harmony front end at harmonydata.ac.uk
5353
@return: a URL which you can click which will take you to the browser.
5454
"""
55-
instrument_serialised_as_json = json.dumps(instrument.dict())
55+
instrument_serialised_as_json = json.dumps(instrument.model_dump())
5656
instrument_json_b64_encoded_bytes = base64.urlsafe_b64encode(instrument_serialised_as_json.encode('utf-8'))
5757
instrument_json_b64_encoded_str = instrument_json_b64_encoded_bytes.decode("utf-8")
5858

tests/test_convert_excel_openpyxl.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from harmony import convert_excel_to_instruments
3434
from harmony.schemas.requests.text import RawFile
3535

36-
xlsx_gad_7_2_questions = RawFile.parse_obj({
36+
xlsx_gad_7_2_questions = RawFile.model_validate({
3737
"file_id": "1d66bce4b80c4b0eaefe33f00cddedef",
3838
"file_name": "GAD-7.xlsx",
3939
"file_type": "xlsx",

tests/test_convert_excel_xlsxwriter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
sys.path.append("../src")
3535

36-
xlsx_gad_7_2_questions = RawFile.parse_obj({
36+
xlsx_gad_7_2_questions = RawFile.model_validate({
3737
"file_id": "1d66bce4b80c4b0eaefe33f00cddedef",
3838
"file_name": "GAD-7.xlsx",
3939
"file_type": "xlsx",

tests/test_convert_pdf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from harmony.schemas.requests.text import RawFile
3535
from harmony import download_models
3636

37-
pdf_gad_7_2_questions = RawFile.parse_obj({
37+
pdf_gad_7_2_questions = RawFile.model_validate({
3838
"file_id": "d39f31718513413fbfc620c6b6135d0c",
3939
"file_name": "GAD-7.pdf",
4040
"file_type": "pdf",

tests/test_convert_text.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from harmony import convert_text_to_instruments
3434
from harmony.schemas.requests.text import RawFile
3535

36-
txt_gad_7_2_questions = RawFile.parse_obj({
36+
txt_gad_7_2_questions = RawFile.model_validate({
3737
"file_id": "d39f31718513413fbfc620c6b6135d0c",
3838
"file_name": "GAD-7.txt",
3939
"file_type": "txt",

tests/test_match.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
question_text="Durante as últimas 2 semanas, com que freqüência você foi incomodado/a pelos problemas abaixo?")]
4444
instrument_pt = Instrument(questions=questions_pt, language="pt")
4545

46-
instrument_1 = Instrument.parse_obj({
46+
instrument_1 = Instrument.model_validate({
4747
"file_id": "fd60a9a64b1b4078a68f4bc06f20253c",
4848
"instrument_id": "7829ba96f48e4848abd97884911b6795",
4949
"instrument_name": "GAD-7 English",
@@ -80,7 +80,7 @@
8080
}
8181
)
8282

83-
instrument_2 = Instrument.parse_obj({
83+
instrument_2 = Instrument.model_validate({
8484
"file_id": "fd60a9a64b1b4078a68f4bc06f20253c",
8585
"instrument_id": "7829ba96f48e4848abd97884911b6795",
8686
"instrument_name": "GAD-7 Portuguese",

tests/test_pdf_tables.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from harmony import download_models
3636

3737

38-
pdf_empty_table = RawFile.parse_obj({
38+
pdf_empty_table = RawFile.model_validate({
3939
"file_id": "d39f31718513413fbfc620c6b6135d0c",
4040
"file_name": "GAD-7.pdf",
4141
"file_type": "pdf",
@@ -44,7 +44,7 @@
4444
"content":""
4545
})
4646

47-
pdf_non_empty_table = RawFile.parse_obj({
47+
pdf_non_empty_table = RawFile.model_validate({
4848
"file_id": "d39f31718513413fbfc620c6b6135d0c",
4949
"file_name": "GAD-7.pdf",
5050
"file_type": "pdf",

0 commit comments

Comments
 (0)