Skip to content

Commit c466512

Browse files
authored
Merge branch 'main' into main
2 parents c620bf3 + 91222db commit c466512

File tree

18 files changed

+95
-40
lines changed

18 files changed

+95
-40
lines changed

giskard/core/model_validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def validate_model_loading_and_saving(model: BaseModel):
147147
with tempfile.TemporaryDirectory(prefix="giskard-model-") as f:
148148
model.save(f)
149149

150-
with open(f + "/giskard-model-meta.yaml") as yaml_f:
150+
with open(f + "/giskard-model-meta.yaml", encoding="utf-8") as yaml_f:
151151
saved_meta = yaml.load(yaml_f, Loader=yaml.Loader)
152152

153153
meta = ModelMeta(

giskard/core/savable.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def _get_meta_endpoint(cls, uuid: str, project_key: str) -> str:
5454
return posixpath.join("project", project_key, cls._get_name(), uuid)
5555

5656
def _save_meta_locally(self, local_dir):
57-
with open(Path(local_dir) / "meta.yaml", "w") as f:
57+
with open(Path(local_dir) / "meta.yaml", "w", encoding="utf-8") as f:
5858
yaml.dump(self.meta, f)
5959

6060

@@ -70,7 +70,7 @@ def _load_meta_locally(cls, local_dir, uuid: str) -> Optional[SMT]:
7070
if meta is not None:
7171
return meta
7272

73-
with open(local_dir / "meta.yaml", "r") as f:
73+
with open(local_dir / "meta.yaml", "r", encoding="utf-8") as f:
7474
return yaml.load(f, Loader=yaml.Loader)
7575

7676
@classmethod

giskard/core/suite.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ def to_json(self, filename=None):
162162
"metric_value": suite_result.result.metric,
163163
}
164164
if filename is not None:
165-
with open(filename, "w") as json_file:
166-
json.dump(results, json_file, indent=4)
165+
with open(filename, "w", encoding="utf-8") as json_file:
166+
json.dump(results, json_file, indent=4, ensure_ascii=False)
167167
else:
168168
return json.dumps(results, indent=4)
169169

@@ -628,8 +628,8 @@ def save(self, folder: str):
628628

629629
json_content = self._to_json(folder_path, saved_uuid_status)
630630

631-
with open(folder_path / "suite.json", "w") as f:
632-
json.dump(json_content, f)
631+
with open(folder_path / "suite.json", "w", encoding="utf-8") as f:
632+
json.dump(json_content, f, ensure_ascii=False)
633633

634634
analytics.track("lib:test_suite:saved")
635635

@@ -843,7 +843,7 @@ def _contains_test(self, test: TestFunctionMeta):
843843
def load(cls, folder: str) -> "Suite":
844844
folder_path = Path(folder)
845845

846-
with open(folder_path / "suite.json", "r") as f:
846+
with open(folder_path / "suite.json", "r", encoding="utf-8") as f:
847847
suite_json = json.load(f)
848848

849849
suite = Suite(name=suite_json.get("name", "Unnamed test suite"))

giskard/datasets/base/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ def cast_column_to_dtypes(df, column_dtypes):
525525
@classmethod
526526
def load(cls, local_path: str):
527527
# load metadata
528-
with open(Path(local_path) / "giskard-dataset-meta.yaml", "r") as meta_f:
528+
with open(Path(local_path) / "giskard-dataset-meta.yaml", "r", encoding="utf-8") as meta_f:
529529
meta = yaml.safe_load(meta_f)
530530

531531
# load data
@@ -560,7 +560,7 @@ def save(self, local_path: str):
560560
f.write(compressed_bytes)
561561
original_size_bytes, compressed_size_bytes = len(uncompressed_bytes), len(compressed_bytes)
562562

563-
with open(Path(local_path) / "giskard-dataset-meta.yaml", "w") as meta_f:
563+
with open(Path(local_path) / "giskard-dataset-meta.yaml", "w", encoding="utf-8") as meta_f:
564564
yaml.dump(
565565
{
566566
"id": str(self.id),

giskard/models/base/wrapper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def save_model_postprocessing_function(self, local_path: Union[str, Path], *_arg
230230
cloudpickle.dump(self.model_postprocessing_function, f, protocol=pickle.DEFAULT_PROTOCOL)
231231

232232
def save_wrapper_meta(self, local_path, *_args, **_kwargs):
233-
with open(Path(local_path) / "giskard-model-wrapper-meta.yaml", "w") as f:
233+
with open(Path(local_path) / "giskard-model-wrapper-meta.yaml", "w", encoding="utf-8") as f:
234234
yaml.dump(
235235
{
236236
"batch_size": self.batch_size,
@@ -313,7 +313,7 @@ def load_model_postprocessing_function(cls, local_path: Union[str, Path], *_args
313313
def load_wrapper_meta(cls, local_dir, *args, **kwargs):
314314
wrapper_meta_file = Path(local_dir) / "giskard-model-wrapper-meta.yaml"
315315
if wrapper_meta_file.exists():
316-
with open(wrapper_meta_file) as f:
316+
with open(wrapper_meta_file, encoding="utf-8") as f:
317317
wrapper_meta = yaml.load(f, Loader=yaml.Loader)
318318
wrapper_meta["batch_size"] = int(wrapper_meta["batch_size"]) if wrapper_meta["batch_size"] else None
319319
return wrapper_meta

giskard/models/huggingface.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class explicitly using :class:`giskard.models.huggingface.HuggingFaceModel`.
9292
the `model_postprocessing_function` argument. This function should take the
9393
raw output of your model and return a numpy array of probabilities.
9494
"""
95+
9596
from typing import Any, Callable, Iterable, Optional, Tuple, Union
9697

9798
import logging
@@ -199,7 +200,7 @@ def __init__(
199200
def load_model(cls, local_path, model_py_ver: Optional[Tuple[str, str, str]] = None, *args, **kwargs):
200201
huggingface_meta_file = Path(local_path) / "giskard-model-huggingface-meta.yaml"
201202
if huggingface_meta_file.exists():
202-
with open(huggingface_meta_file) as f:
203+
with open(huggingface_meta_file, encoding="utf-8") as f:
203204
huggingface_meta = yaml.load(f, Loader=yaml.Loader)
204205

205206
if huggingface_meta["pipeline_task"]:
@@ -208,7 +209,7 @@ def load_model(cls, local_path, model_py_ver: Optional[Tuple[str, str, str]] = N
208209
return huggingface_meta["huggingface_module"].from_pretrained(local_path)
209210

210211
def save_huggingface_meta(self, local_path, *args, **kwargs):
211-
with open(Path(local_path) / "giskard-model-huggingface-meta.yaml", "w") as f:
212+
with open(Path(local_path) / "giskard-model-huggingface-meta.yaml", "w", encoding="utf-8") as f:
212213
yaml.dump(
213214
{
214215
"huggingface_module": self.huggingface_module,

giskard/models/pytorch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def _convert_to_numpy(self, raw_predictions):
200200
return super()._convert_to_numpy(raw_predictions)
201201

202202
def save_pytorch_meta(self, local_path, *_args, **_kwargs):
203-
with open(Path(local_path) / "giskard-model-pytorch-meta.yaml", "w") as f:
203+
with open(Path(local_path) / "giskard-model-pytorch-meta.yaml", "w", encoding="utf-8") as f:
204204
yaml.dump(
205205
{
206206
"device": self.device,
@@ -224,7 +224,7 @@ def load(cls, local_dir, model_py_ver: Optional[Tuple[str, str, str]] = None, *a
224224
def load_pytorch_meta(cls, local_dir):
225225
pytorch_meta_file = Path(local_dir) / "giskard-model-pytorch-meta.yaml"
226226
if pytorch_meta_file.exists():
227-
with open(pytorch_meta_file) as f:
227+
with open(pytorch_meta_file, encoding="utf-8") as f:
228228
pytorch_meta = yaml.load(f, Loader=yaml.Loader)
229229
pytorch_meta["device"] = pytorch_meta.get("device")
230230
pytorch_meta["torch_dtype"] = pytorch_meta.get("torch_dtype")

giskard/rag/report.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,11 @@ def load(
193193
The embedding model to use inside the knowledge base. If not provided, the default model will be used.
194194
"""
195195
path = Path(folder_path)
196-
knowledge_base_meta = json.load(open(path / "knowledge_base_meta.json", "r"))
196+
knowledge_base_meta = json.load(open(path / "knowledge_base_meta.json", "r", encoding="utf-8"))
197197
knowledge_base_data = pd.read_json(path / "knowledge_base.jsonl", orient="records", lines=True)
198198
testset = QATestset.load(path / "testset.jsonl")
199199

200-
answers = json.load(open(path / "agent_answer.json", "r"))
200+
answers = json.load(open(path / "agent_answer.json", "r", encoding="utf-8"))
201201
model_outputs = [AgentAnswer(**answer) for answer in answers]
202202

203203
topics = {int(k): topic for k, topic in knowledge_base_meta.pop("topics", None).items()}
@@ -219,9 +219,9 @@ def load(
219219

220220
metrics_results = {}
221221
if (path / "metrics_results.json").exists():
222-
metrics_results = json.load(open(path / "metrics_results.json", "r"))
222+
metrics_results = json.load(open(path / "metrics_results.json", "r", encoding="utf-8"))
223223

224-
report_details = json.load(open(path / "report_details.json", "r"))
224+
report_details = json.load(open(path / "report_details.json", "r", encoding="utf-8"))
225225
testset._dataframe.index = testset._dataframe.index.astype(str)
226226

227227
report = cls(testset, model_outputs, metrics_results, knowledge_base)

giskard/registry/giskard_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def _load_meta_locally(cls, local_dir, uuid: str) -> Optional[TestFunctionMeta]:
7373
if meta is not None:
7474
return meta
7575

76-
with open(local_dir / "meta.yaml", "r") as f:
76+
with open(local_dir / "meta.yaml", "r", encoding="utf-8") as f:
7777
return yaml.load(f, Loader=yaml.Loader)
7878

7979
@classmethod

giskard/scanner/report.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ def to_json(self, filename=None):
9090
results[issue.detector_name][issue.level] = []
9191
results[issue.detector_name][issue.level].append(issue.description)
9292
if filename is not None:
93-
with open(filename, "w") as json_file:
94-
json.dump(results, json_file, indent=4)
93+
with open(filename, "w", encoding="utf-8") as json_file:
94+
json.dump(results, json_file, indent=4, ensure_ascii=False)
9595
else:
9696
return json.dumps(results, indent=4)
9797

@@ -115,7 +115,7 @@ def to_html(self, filename=None, embed=False):
115115
html = widget.render_html(embed=embed)
116116

117117
if filename is not None:
118-
with open(filename, "w") as f:
118+
with open(filename, "w", encoding="utf-8") as f:
119119
f.write(html)
120120
return
121121

@@ -139,7 +139,7 @@ def to_markdown(self, filename=None, template="summary"):
139139
markdown = widget.render_markdown(template=template)
140140

141141
if filename is not None:
142-
with open(filename, "w") as f:
142+
with open(filename, "w", encoding="utf-8") as f:
143143
f.write(markdown)
144144
return
145145

@@ -349,7 +349,7 @@ def to_avid(self, filename=None):
349349
]
350350

351351
if filename is not None:
352-
with open(filename, "w") as f, warnings.catch_warnings():
352+
with open(filename, "w", encoding="utf-8") as f, warnings.catch_warnings():
353353
warnings.filterwarnings("ignore", category=DeprecationWarning) # we need to support both pydantic 1 & 2
354354
f.writelines(r.json() + "\n" for r in reports)
355355
return
@@ -373,7 +373,7 @@ def generate_rails(self, filename=None, colang_version="1.0"):
373373
_rails = generate_rails_from_scan_report(self, colang_version=colang_version)
374374

375375
if filename:
376-
with open(filename, "a") as f:
376+
with open(filename, "a", encoding="utf-8") as f:
377377
f.write(_rails)
378378
return
379379

0 commit comments

Comments
 (0)