Skip to content
Open
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
12 changes: 6 additions & 6 deletions src/promptflow-evals/promptflow/evals/evaluate/_evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,12 @@ def _validate_and_load_data(target, data, evaluators, output_path, azure_ai_proj
if not isinstance(evaluation_name, str):
raise ValueError("evaluation_name must be a string.")

try:
initial_data_df = pd.read_json(data, lines=True)
except Exception as e:
raise ValueError(
f"Failed to load data from {data}. Please validate it is a valid jsonl data. Error: {str(e)}."
) from e
try:
initial_data_df = pd.read_json(data, lines=True, encoding="utf-8-sig")
except Exception as e:
raise ValueError(
f"Failed to load data from {data}. Please validate it is a valid jsonl data. Error: {str(e)}."
) from e

return initial_data_df

Expand Down
20 changes: 19 additions & 1 deletion src/promptflow-evals/tests/evals/unittests/test_evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
from promptflow.client import PFClient
from promptflow.evals._constants import DEFAULT_EVALUATION_RESULTS_FILE_NAME
from promptflow.evals.evaluate import evaluate
from promptflow.evals.evaluate._evaluate import _aggregate_metrics, _apply_target_to_data, _rename_columns_conditionally
from promptflow.evals.evaluate._evaluate import (
_aggregate_metrics,
_apply_target_to_data,
_rename_columns_conditionally,
_validate_and_load_data,
)
from promptflow.evals.evaluate._utils import _apply_column_mapping, _trace_destination_from_project_scope
from promptflow.evals.evaluators import (
ContentSafetyEvaluator,
Expand Down Expand Up @@ -123,6 +128,19 @@ def test_evaluate_invalid_jsonl_data(self, mock_model_config, invalid_jsonl_file
assert "Failed to load data from " in exc_info.value.args[0]
assert "Please validate it is a valid jsonl data" in exc_info.value.args[0]

def test_validate_and_load_data_accepts_utf8_sig_jsonl(self, tmp_path):
data_file = tmp_path / "evaluate_test_data_utf8_sig.jsonl"
data_file.write_text(
'{"question": "How are you?", "answer": "Fine", "ground_truth": "Fine"}\n',
encoding="utf-8-sig",
)

data = _validate_and_load_data(None, str(data_file), {"g": F1ScoreEvaluator()}, None, None, None)

assert data.to_dict(orient="records") == [
{"question": "How are you?", "answer": "Fine", "ground_truth": "Fine"}
]

def test_evaluate_missing_required_inputs(self, missing_columns_jsonl_file):
with pytest.raises(ValueError) as exc_info:
evaluate(data=missing_columns_jsonl_file, evaluators={"g": F1ScoreEvaluator()})
Expand Down
Loading