Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Pydantic 2.8.2 #51

Merged
merged 3 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ classifiers=[
# core dependencies of harmony
# this set should be kept minimal!
dependencies = [
"pydantic==1.10.7; python_version <= '3.12'",
"pydantic==2.8.2; python_version <= '3.12'",
"pandas==2.0.0; python_version <= '3.12'",
"tika==2.6.0; python_version <= '3.12'",
"lxml==4.9.2; python_version <= '3.12'",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pydantic==1.10.7
pydantic==2.8.2
pandas==2.0.0
tika==2.6.0
lxml==4.9.2
Expand Down
2 changes: 1 addition & 1 deletion src/harmony/examples.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/harmony/matching/matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def match_instruments_with_function(
ctrs[all_questions[idx].instrument_id] = Counter()
for topic in mhc_all_metadatas[mhc_item_idx]["topics"]:
ctrs[all_questions[idx].instrument_id][topic] += 1
all_questions[idx].nearest_match_from_mhc_auto = mhc_questions[mhc_item_idx].dict()
all_questions[idx].nearest_match_from_mhc_auto = mhc_questions[mhc_item_idx].model_dump()
strength_of_match = similarities_mhc[idx, mhc_item_idx]
all_questions[idx].topics_strengths = {topic: float(strength_of_match)}

Expand Down
73 changes: 34 additions & 39 deletions src/harmony/schemas/requests/text.py

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/harmony/schemas/responses/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from harmony.schemas.requests.text import Instrument
from harmony.schemas.requests.text import Question
from pydantic import BaseModel, Field
from pydantic import BaseModel, Field, RootModel


class MatchResponse(BaseModel):
Expand All @@ -42,8 +42,8 @@ class MatchResponse(BaseModel):
)


class InstrumentList(BaseModel):
__root__: List[Instrument]
class InstrumentList(RootModel):
root: List[Instrument]


class CacheResponse(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion src/harmony/util/instrument_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def import_instrument_into_harmony_web(instrument: Instrument, harmony_fe_base_u
@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
@return: a URL which you can click which will take you to the browser.
"""
instrument_serialised_as_json = json.dumps(instrument.dict())
instrument_serialised_as_json = json.dumps(instrument.model_dump())
instrument_json_b64_encoded_bytes = base64.urlsafe_b64encode(instrument_serialised_as_json.encode('utf-8'))
instrument_json_b64_encoded_str = instrument_json_b64_encoded_bytes.decode("utf-8")

Expand Down
2 changes: 1 addition & 1 deletion tests/test_convert_excel_openpyxl.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from harmony import convert_excel_to_instruments
from harmony.schemas.requests.text import RawFile

xlsx_gad_7_2_questions = RawFile.parse_obj({
xlsx_gad_7_2_questions = RawFile.model_validate({
"file_id": "1d66bce4b80c4b0eaefe33f00cddedef",
"file_name": "GAD-7.xlsx",
"file_type": "xlsx",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_convert_excel_xlsxwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

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

xlsx_gad_7_2_questions = RawFile.parse_obj({
xlsx_gad_7_2_questions = RawFile.model_validate({
"file_id": "1d66bce4b80c4b0eaefe33f00cddedef",
"file_name": "GAD-7.xlsx",
"file_type": "xlsx",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_convert_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from harmony.schemas.requests.text import RawFile
from harmony import download_models

pdf_gad_7_2_questions = RawFile.parse_obj({
pdf_gad_7_2_questions = RawFile.model_validate({
"file_id": "d39f31718513413fbfc620c6b6135d0c",
"file_name": "GAD-7.pdf",
"file_type": "pdf",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_convert_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from harmony import convert_text_to_instruments
from harmony.schemas.requests.text import RawFile

txt_gad_7_2_questions = RawFile.parse_obj({
txt_gad_7_2_questions = RawFile.model_validate({
"file_id": "d39f31718513413fbfc620c6b6135d0c",
"file_name": "GAD-7.txt",
"file_type": "txt",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
question_text="Durante as últimas 2 semanas, com que freqüência você foi incomodado/a pelos problemas abaixo?")]
instrument_pt = Instrument(questions=questions_pt, language="pt")

instrument_1 = Instrument.parse_obj({
instrument_1 = Instrument.model_validate({
"file_id": "fd60a9a64b1b4078a68f4bc06f20253c",
"instrument_id": "7829ba96f48e4848abd97884911b6795",
"instrument_name": "GAD-7 English",
Expand Down Expand Up @@ -80,7 +80,7 @@
}
)

instrument_2 = Instrument.parse_obj({
instrument_2 = Instrument.model_validate({
"file_id": "fd60a9a64b1b4078a68f4bc06f20253c",
"instrument_id": "7829ba96f48e4848abd97884911b6795",
"instrument_name": "GAD-7 Portuguese",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_pdf_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from harmony import download_models


pdf_empty_table = RawFile.parse_obj({
pdf_empty_table = RawFile.model_validate({
"file_id": "d39f31718513413fbfc620c6b6135d0c",
"file_name": "GAD-7.pdf",
"file_type": "pdf",
Expand All @@ -44,7 +44,7 @@
"content":""
})

pdf_non_empty_table = RawFile.parse_obj({
pdf_non_empty_table = RawFile.model_validate({
"file_id": "d39f31718513413fbfc620c6b6135d0c",
"file_name": "GAD-7.pdf",
"file_type": "pdf",
Expand Down
Loading