robert 2.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- robert/__init__.py +9 -0
- robert/__main__.py +20 -0
- robert/_version.py +3 -0
- robert/api.py +646 -0
- robert/aqme.py +280 -0
- robert/argument_parser.py +98 -0
- robert/checkml.py +433 -0
- robert/checkml_score.py +50 -0
- robert/curate.py +217 -0
- robert/evaluate_bot_retrieval.py +125 -0
- robert/evaluate_bot_support.py +102 -0
- robert/evaluate_workflow_summaries.py +87 -0
- robert/export_bot_docs_knowledge.py +1632 -0
- robert/generate.py +249 -0
- robert/generate_utils.py +311 -0
- robert/gui_easyrob/__init__.py +0 -0
- robert/gui_easyrob/assets/gif_easyrob.gif +0 -0
- robert/gui_easyrob/bot/__init__.py +47 -0
- robert/gui_easyrob/bot/answer_metadata.py +198 -0
- robert/gui_easyrob/bot/bot_context.py +679 -0
- robert/gui_easyrob/bot/bot_engine.py +1100 -0
- robert/gui_easyrob/bot/bot_panel.py +1231 -0
- robert/gui_easyrob/bot/bot_rag.py +1178 -0
- robert/gui_easyrob/bot/bot_window.py +39 -0
- robert/gui_easyrob/bot/bot_worker.py +149 -0
- robert/gui_easyrob/bot/credential_store.py +143 -0
- robert/gui_easyrob/bot/error_parser.py +105 -0
- robert/gui_easyrob/bot/evidence_policy.py +164 -0
- robert/gui_easyrob/bot/heuristics.py +859 -0
- robert/gui_easyrob/bot/icons.py +56 -0
- robert/gui_easyrob/bot/input_csv_audit.py +212 -0
- robert/gui_easyrob/bot/knowledge/aqme_context.json +5907 -0
- robert/gui_easyrob/bot/knowledge/robert_context.json +4817 -0
- robert/gui_easyrob/bot/knowledge/ui_context.json +8293 -0
- robert/gui_easyrob/bot/knowledge_schema.py +1252 -0
- robert/gui_easyrob/bot/knowledge_sources/aqme_user_guidance.json +442 -0
- robert/gui_easyrob/bot/knowledge_sources/coverage_manifest.json +95 -0
- robert/gui_easyrob/bot/knowledge_sources/robert_user_guidance.json +471 -0
- robert/gui_easyrob/bot/knowledge_sources/ui_user_guidance.json +1312 -0
- robert/gui_easyrob/bot/llm_providers.py +1573 -0
- robert/gui_easyrob/bot/online_docs.py +105 -0
- robert/gui_easyrob/bot/prompt_policy.py +575 -0
- robert/gui_easyrob/bot/question_intent.py +562 -0
- robert/gui_easyrob/bot/response_quality.py +104 -0
- robert/gui_easyrob/bot/result_insights.py +225 -0
- robert/gui_easyrob/bot/token_usage.py +75 -0
- robert/gui_easyrob/bot/workflow_results.py +1396 -0
- robert/gui_easyrob/checkml_launcher.py +15 -0
- robert/gui_easyrob/easyrob.py +29 -0
- robert/gui_easyrob/easyrob_launcher.py +113 -0
- robert/gui_easyrob/main/__init__.py +9 -0
- robert/gui_easyrob/main/window.py +5152 -0
- robert/gui_easyrob/result_navigation.py +14 -0
- robert/gui_easyrob/tabs/__init__.py +23 -0
- robert/gui_easyrob/tabs/advanced_options.py +370 -0
- robert/gui_easyrob/tabs/aqme.py +1234 -0
- robert/gui_easyrob/tabs/checkml.py +898 -0
- robert/gui_easyrob/tabs/images.py +427 -0
- robert/gui_easyrob/tabs/interactive_predictions.py +555 -0
- robert/gui_easyrob/tabs/molssi.py +447 -0
- robert/gui_easyrob/tabs/predictions.py +484 -0
- robert/gui_easyrob/tabs/result_catalog.py +170 -0
- robert/gui_easyrob/tabs/results.py +490 -0
- robert/gui_easyrob/tabs/results_workspace.py +120 -0
- robert/gui_easyrob/test_bot_input_csv_audit.py +152 -0
- robert/gui_easyrob/test_bot_question_routing.py +383 -0
- robert/gui_easyrob/test_bot_result_analysis.py +356 -0
- robert/gui_easyrob/test_bot_retrieval_evaluation.py +110 -0
- robert/gui_easyrob/test_bot_ui_integration.py +278 -0
- robert/gui_easyrob/test_checkml_app_mode.py +124 -0
- robert/gui_easyrob/test_checkml_completion.py +57 -0
- robert/gui_easyrob/test_checkml_defaults.py +37 -0
- robert/gui_easyrob/test_checkml_result_summary.py +113 -0
- robert/gui_easyrob/test_checkml_web_mode.py +57 -0
- robert/gui_easyrob/test_dialog_layout.py +33 -0
- robert/gui_easyrob/test_gui_bot_regressions.py +320 -0
- robert/gui_easyrob/test_molssi_auto.py +569 -0
- robert/gui_easyrob/test_tutorial_view.py +215 -0
- robert/gui_easyrob/tutorials/check_model.md +25 -0
- robert/gui_easyrob/tutorials/chemdraw.md +49 -0
- robert/gui_easyrob/tutorials/csv.md +53 -0
- robert/gui_easyrob/tutorials/descriptors.md +21 -0
- robert/gui_easyrob/tutorials/overview.md +65 -0
- robert/gui_easyrob/tutorials/predictions.md +25 -0
- robert/gui_easyrob/tutorials/robbot.md +29 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_7.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_10.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_11.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_12.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_13.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_7.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_8.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_9.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_7.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_8.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_9.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_7.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_8.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_1_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_7.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_8.png +0 -0
- robert/gui_easyrob/utils/__init__.py +0 -0
- robert/gui_easyrob/utils/aqme_utils.py +238 -0
- robert/gui_easyrob/utils/molssi_utils.py +584 -0
- robert/gui_easyrob/utils/predictions_utils.py +985 -0
- robert/gui_easyrob/utils/utils_gui.py +738 -0
- robert/gui_easyrob/version.py +68 -0
- robert/gui_easyrob/web/app.css +484 -0
- robert/gui_easyrob/web/app.html +134 -0
- robert/gui_easyrob/web/app.js +764 -0
- robert/gui_easyrob/web/checkml_brand.png +0 -0
- robert/gui_easyrob/web/easyrob_background.gif +0 -0
- robert/gui_easyrob/web/easyrob_background.png +0 -0
- robert/gui_easyrob/web/images.css +89 -0
- robert/gui_easyrob/web/images.html +39 -0
- robert/gui_easyrob/web/images.js +101 -0
- robert/gui_easyrob/web/results.js +499 -0
- robert/gui_easyrob/web/robert_brand.png +0 -0
- robert/gui_easyrob/web_dialogs.py +64 -0
- robert/gui_easyrob/web_results.py +253 -0
- robert/gui_easyrob/web_shell.py +684 -0
- robert/gui_easyrob/workflow_progress.py +89 -0
- robert/gui_easyrob/workflow_run_lock.py +27 -0
- robert/icons/CheckML_icon.png +0 -0
- robert/icons/Robert_icon.png +0 -0
- robert/icons/Robert_logo.jpg +0 -0
- robert/icons/Robert_logo_transparent.png +0 -0
- robert/icons/documentation_icon.png +0 -0
- robert/icons/info_icon.png +0 -0
- robert/icons/pdf_icon.png +0 -0
- robert/icons/play_icon.png +0 -0
- robert/icons/stop_icon.png +0 -0
- robert/icons/youtube_icon.ico +0 -0
- robert/predict.py +193 -0
- robert/predict_utils.py +410 -0
- robert/report/CheckML_logo.jpg +0 -0
- robert/report/GENERATE.png +0 -0
- robert/report/Robert_icon.ico +0 -0
- robert/report/Robert_logo.jpg +0 -0
- robert/report/Robert_logo1.jpg +0 -0
- robert/report/abbrev.png +0 -0
- robert/report/adv_anal.png +0 -0
- robert/report/checkml_pass.svg +3 -0
- robert/report/checkml_unclear.svg +3 -0
- robert/report/checkml_warning.svg +3 -0
- robert/report/features.png +0 -0
- robert/report/outliers.png +0 -0
- robert/report/pred.png +0 -0
- robert/report/repro.png +0 -0
- robert/report/robust_x.png +0 -0
- robert/report/robust_y_high.png +0 -0
- robert/report/robust_y_low.png +0 -0
- robert/report/score.png +0 -0
- robert/report/score_0.jpg +0 -0
- robert/report/score_1.jpg +0 -0
- robert/report/score_10.jpg +0 -0
- robert/report/score_2.jpg +0 -0
- robert/report/score_3.jpg +0 -0
- robert/report/score_4.jpg +0 -0
- robert/report/score_5.jpg +0 -0
- robert/report/score_6.jpg +0 -0
- robert/report/score_7.jpg +0 -0
- robert/report/score_8.jpg +0 -0
- robert/report/score_9.jpg +0 -0
- robert/report/score_gray_0.jpg +0 -0
- robert/report/score_gray_1.jpg +0 -0
- robert/report/score_gray_10.jpg +0 -0
- robert/report/score_gray_2.jpg +0 -0
- robert/report/score_gray_3.jpg +0 -0
- robert/report/score_gray_4.jpg +0 -0
- robert/report/score_gray_5.jpg +0 -0
- robert/report/score_gray_6.jpg +0 -0
- robert/report/score_gray_7.jpg +0 -0
- robert/report/score_gray_8.jpg +0 -0
- robert/report/score_gray_9.jpg +0 -0
- robert/report/score_w_1_0.jpg +0 -0
- robert/report/score_w_1_1.jpg +0 -0
- robert/report/score_w_2_0.jpg +0 -0
- robert/report/score_w_2_1.jpg +0 -0
- robert/report/score_w_2_2.jpg +0 -0
- robert/report/score_w_2_gray_0.jpg +0 -0
- robert/report/score_w_2_gray_1.jpg +0 -0
- robert/report/score_w_2_gray_2.jpg +0 -0
- robert/report/score_w_3_0.jpg +0 -0
- robert/report/score_w_3_1.jpg +0 -0
- robert/report/score_w_3_2.jpg +0 -0
- robert/report/score_w_3_3.jpg +0 -0
- robert/report/score_w_4_0.jpg +0 -0
- robert/report/score_w_4_1.JPG +0 -0
- robert/report/score_w_4_2.jpg +0 -0
- robert/report/score_w_4_3.jpg +0 -0
- robert/report/score_w_4_4.jpg +0 -0
- robert/report/transpa.png +0 -0
- robert/report/y_distrib.png +0 -0
- robert/report.py +2880 -0
- robert/report_utils.py +2270 -0
- robert/robert.py +181 -0
- robert/utils.py +4763 -0
- robert/verify.py +606 -0
- robert-2.2.0.dist-info/METADATA +55 -0
- robert-2.2.0.dist-info/RECORD +261 -0
- robert-2.2.0.dist-info/WHEEL +5 -0
- robert-2.2.0.dist-info/entry_points.txt +3 -0
- robert-2.2.0.dist-info/licenses/LICENSE +21 -0
- robert-2.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""Code-generated icons for the EasyROB bot UI."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from PySide6.QtCore import QPointF, Qt
|
|
6
|
+
from PySide6.QtGui import QColor, QIcon, QPainter, QPen, QPixmap
|
|
7
|
+
|
|
8
|
+
__all__ = ["create_bot_icon"]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def create_bot_icon(size: int = 18) -> QIcon:
|
|
12
|
+
icon_size = max(int(size or 18), 12)
|
|
13
|
+
pixmap = QPixmap(icon_size, icon_size)
|
|
14
|
+
pixmap.fill(Qt.GlobalColor.transparent)
|
|
15
|
+
|
|
16
|
+
painter = QPainter(pixmap)
|
|
17
|
+
painter.setRenderHint(QPainter.RenderHint.Antialiasing, True)
|
|
18
|
+
|
|
19
|
+
stroke = QColor("#1f2937")
|
|
20
|
+
fill = QColor("#d7eef8")
|
|
21
|
+
accent = QColor("#ff8a3d")
|
|
22
|
+
eye = QColor("#0f172a")
|
|
23
|
+
|
|
24
|
+
head_rect = pixmap.rect().adjusted(3, 4, -3, -3)
|
|
25
|
+
painter.setPen(QPen(stroke, 1.4))
|
|
26
|
+
painter.setBrush(fill)
|
|
27
|
+
painter.drawRoundedRect(head_rect, 3.2, 3.2)
|
|
28
|
+
|
|
29
|
+
painter.drawLine(
|
|
30
|
+
QPointF(icon_size * 0.5, 1.7),
|
|
31
|
+
QPointF(icon_size * 0.5, 4.5),
|
|
32
|
+
)
|
|
33
|
+
painter.setBrush(accent)
|
|
34
|
+
painter.drawEllipse(QPointF(icon_size * 0.5, 1.9), 1.35, 1.35)
|
|
35
|
+
|
|
36
|
+
painter.setBrush(eye)
|
|
37
|
+
painter.setPen(Qt.PenStyle.NoPen)
|
|
38
|
+
painter.drawEllipse(QPointF(icon_size * 0.37, icon_size * 0.48), 1.2, 1.2)
|
|
39
|
+
painter.drawEllipse(QPointF(icon_size * 0.63, icon_size * 0.48), 1.2, 1.2)
|
|
40
|
+
|
|
41
|
+
painter.setPen(QPen(stroke, 1.1))
|
|
42
|
+
painter.drawLine(
|
|
43
|
+
QPointF(icon_size * 0.37, icon_size * 0.68),
|
|
44
|
+
QPointF(icon_size * 0.63, icon_size * 0.68),
|
|
45
|
+
)
|
|
46
|
+
painter.drawLine(
|
|
47
|
+
QPointF(3.0, icon_size * 0.46),
|
|
48
|
+
QPointF(1.4, icon_size * 0.38),
|
|
49
|
+
)
|
|
50
|
+
painter.drawLine(
|
|
51
|
+
QPointF(icon_size - 3.0, icon_size * 0.46),
|
|
52
|
+
QPointF(icon_size - 1.4, icon_size * 0.38),
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
painter.end()
|
|
56
|
+
return QIcon(pixmap)
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"""Bounded structural checks for CSVs selected in the EasyROB GUI."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import csv
|
|
6
|
+
import math
|
|
7
|
+
import re
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Iterable
|
|
11
|
+
|
|
12
|
+
from .result_insights import ResultInsight
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
_MAX_SCAN_ROWS = 500
|
|
16
|
+
_MAX_SCAN_COLUMNS = 500
|
|
17
|
+
_MISSING = {"", "nan", "none", "null", "n/a", "inf", "-inf"}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def is_selected_csv_question(question: str) -> bool:
|
|
21
|
+
"""Identify questions about the user's selected table, not CSV concepts."""
|
|
22
|
+
folded = str(question or "").casefold()
|
|
23
|
+
topic = re.search(r"\b(?:csv|dataset|datos?|data|tabla|archivo|file)\b", folded)
|
|
24
|
+
contextual = re.search(
|
|
25
|
+
r"\b(?:mi|mis|my|our|this|these|este|esta|estos|estas|selected|cargad\w*|subid\w*|"
|
|
26
|
+
r"analiz\w*|revis\w*|inspeccion\w*|problemas?|fallas?|missing|faltan?|"
|
|
27
|
+
r"duplic\w*|filas?|columnas?|rows?|columns?)\b",
|
|
28
|
+
folded,
|
|
29
|
+
)
|
|
30
|
+
return bool(topic and contextual)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@dataclass(frozen=True, slots=True)
|
|
34
|
+
class _CsvProfile:
|
|
35
|
+
insight: ResultInsight
|
|
36
|
+
descriptors: tuple[str, ...] = ()
|
|
37
|
+
smiles: tuple[str, ...] = ()
|
|
38
|
+
inspected: bool = False
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _is_missing(value: str) -> bool:
|
|
42
|
+
return value.strip().casefold() in _MISSING
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _is_finite_number(value: str) -> bool:
|
|
46
|
+
try:
|
|
47
|
+
return math.isfinite(float(value))
|
|
48
|
+
except (TypeError, ValueError):
|
|
49
|
+
return False
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _column_index(header: list[str], wanted: str) -> int | None:
|
|
53
|
+
normalized = wanted.strip().casefold()
|
|
54
|
+
return next((index for index, name in enumerate(header) if name.strip().casefold() == normalized), None)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _profile_csv(
|
|
58
|
+
path: Path,
|
|
59
|
+
role: str,
|
|
60
|
+
target_column: str,
|
|
61
|
+
name_column: str,
|
|
62
|
+
prediction_type: str,
|
|
63
|
+
ignored_columns: set[str],
|
|
64
|
+
) -> _CsvProfile:
|
|
65
|
+
source = path.name
|
|
66
|
+
if not path.is_file():
|
|
67
|
+
return _CsvProfile(ResultInsight("", "", "input_csv", f"{role} CSV is not readable; no rows inspected", source))
|
|
68
|
+
try:
|
|
69
|
+
with path.open("r", encoding="utf-8-sig", errors="replace", newline="") as handle:
|
|
70
|
+
sample = handle.read(4096)
|
|
71
|
+
handle.seek(0)
|
|
72
|
+
try:
|
|
73
|
+
dialect = csv.Sniffer().sniff(sample, delimiters=",;\t")
|
|
74
|
+
except csv.Error:
|
|
75
|
+
dialect = csv.excel
|
|
76
|
+
reader = csv.reader(handle, dialect=dialect, strict=True)
|
|
77
|
+
header = [item.strip() for item in next(reader, [])]
|
|
78
|
+
if not header:
|
|
79
|
+
return _CsvProfile(ResultInsight("", "", "input_csv", f"{role} CSV is empty; no columns inspected", source))
|
|
80
|
+
scanned_header = header[:_MAX_SCAN_COLUMNS]
|
|
81
|
+
target_index = _column_index(scanned_header, target_column) if target_column else None
|
|
82
|
+
smiles_index = _column_index(scanned_header, "SMILES")
|
|
83
|
+
identifier = name_column or next(
|
|
84
|
+
(name for name in ("code_name", "name", "id") if _column_index(scanned_header, name) is not None),
|
|
85
|
+
"",
|
|
86
|
+
)
|
|
87
|
+
identifier_index = _column_index(scanned_header, identifier) if identifier else None
|
|
88
|
+
excluded = {"smiles", "code_name", "name", "id", target_column.strip().casefold(), *ignored_columns}
|
|
89
|
+
descriptor_indexes = tuple(
|
|
90
|
+
index for index, name in enumerate(scanned_header)
|
|
91
|
+
if name and name.casefold() not in excluded
|
|
92
|
+
)
|
|
93
|
+
missing_counts = [0] * len(scanned_header)
|
|
94
|
+
nonnumeric_counts = [0] * len(scanned_header)
|
|
95
|
+
seen_identifiers: set[str] = set()
|
|
96
|
+
seen_smiles: set[str] = set()
|
|
97
|
+
smiles_values: list[str] = []
|
|
98
|
+
repeated_identifiers = repeated_smiles = malformed_rows = rows = 0
|
|
99
|
+
truncated = False
|
|
100
|
+
for row in reader:
|
|
101
|
+
if rows >= _MAX_SCAN_ROWS:
|
|
102
|
+
truncated = True
|
|
103
|
+
break
|
|
104
|
+
rows += 1
|
|
105
|
+
if len(row) != len(header):
|
|
106
|
+
malformed_rows += 1
|
|
107
|
+
for index in range(len(scanned_header)):
|
|
108
|
+
value = row[index].strip() if index < len(row) else ""
|
|
109
|
+
if _is_missing(value):
|
|
110
|
+
missing_counts[index] += 1
|
|
111
|
+
elif index == target_index or index in descriptor_indexes:
|
|
112
|
+
if not _is_finite_number(value):
|
|
113
|
+
nonnumeric_counts[index] += 1
|
|
114
|
+
if identifier_index is not None and identifier_index < len(row):
|
|
115
|
+
value = row[identifier_index].strip()
|
|
116
|
+
if value and value in seen_identifiers:
|
|
117
|
+
repeated_identifiers += 1
|
|
118
|
+
seen_identifiers.add(value)
|
|
119
|
+
if smiles_index is not None and smiles_index < len(row):
|
|
120
|
+
value = row[smiles_index].strip()
|
|
121
|
+
if value:
|
|
122
|
+
repeated_smiles += value in seen_smiles
|
|
123
|
+
seen_smiles.add(value)
|
|
124
|
+
smiles_values.append(value)
|
|
125
|
+
except (OSError, csv.Error, UnicodeError) as exc:
|
|
126
|
+
message = f"{role} CSV could not be inspected ({type(exc).__name__}); no complete profile available"
|
|
127
|
+
return _CsvProfile(ResultInsight("", "", "input_csv", message, source))
|
|
128
|
+
|
|
129
|
+
header_counts: dict[str, int] = {}
|
|
130
|
+
for name in header:
|
|
131
|
+
key = name.casefold()
|
|
132
|
+
header_counts[key] = header_counts.get(key, 0) + 1
|
|
133
|
+
findings = [f"{role} CSV: {rows} rows scanned, {len(header)} columns"]
|
|
134
|
+
if len(header) > _MAX_SCAN_COLUMNS:
|
|
135
|
+
findings.append(f"column scan limited to first {_MAX_SCAN_COLUMNS} columns")
|
|
136
|
+
if truncated:
|
|
137
|
+
findings.append(f"scan limited to first {_MAX_SCAN_ROWS} rows")
|
|
138
|
+
if malformed_rows:
|
|
139
|
+
suffix = "row" if malformed_rows == 1 else "rows"
|
|
140
|
+
findings.append(f"{malformed_rows} {suffix} with a different column count")
|
|
141
|
+
duplicate_headers = [name for name in header if header_counts[name.casefold()] > 1]
|
|
142
|
+
if duplicate_headers:
|
|
143
|
+
findings.append(f"duplicate header: {duplicate_headers[0]}")
|
|
144
|
+
if target_column and target_index is None:
|
|
145
|
+
findings.append(
|
|
146
|
+
"observed target column absent; no error metric can be computed"
|
|
147
|
+
if role == "External" else f"target column {target_column} missing"
|
|
148
|
+
)
|
|
149
|
+
elif target_index is not None:
|
|
150
|
+
count = missing_counts[target_index]
|
|
151
|
+
if count:
|
|
152
|
+
findings.append(f"{count} missing target value{'s' if count != 1 else ''}")
|
|
153
|
+
count = nonnumeric_counts[target_index]
|
|
154
|
+
if count and prediction_type.casefold().startswith("reg"):
|
|
155
|
+
findings.append(f"{count} nonnumeric target value{'s' if count != 1 else ''}")
|
|
156
|
+
for index in descriptor_indexes:
|
|
157
|
+
count = nonnumeric_counts[index]
|
|
158
|
+
if count:
|
|
159
|
+
findings.append(
|
|
160
|
+
f"{count} nonnumeric value{'s' if count != 1 else ''} in descriptor {scanned_header[index][:80]}"
|
|
161
|
+
)
|
|
162
|
+
if repeated_smiles:
|
|
163
|
+
findings.append(f"{repeated_smiles} repeated exact SMILES")
|
|
164
|
+
if repeated_identifiers:
|
|
165
|
+
findings.append(f"{repeated_identifiers} repeated {identifier}")
|
|
166
|
+
missing_descriptors = sorted(
|
|
167
|
+
((scanned_header[index], missing_counts[index]) for index in descriptor_indexes if missing_counts[index]),
|
|
168
|
+
key=lambda item: (-item[1], item[0].casefold()),
|
|
169
|
+
)
|
|
170
|
+
findings.extend(
|
|
171
|
+
f"{name[:80]}: {count}/{rows} missing" for name, count in missing_descriptors[:3]
|
|
172
|
+
)
|
|
173
|
+
if len(missing_descriptors) > 3:
|
|
174
|
+
findings.append(f"{len(missing_descriptors) - 3} more descriptors with missing values")
|
|
175
|
+
findings.append("structural checks only; chemical validity was not assessed")
|
|
176
|
+
insight = ResultInsight("", "", "input_csv", "; ".join(findings), source)
|
|
177
|
+
return _CsvProfile(insight, tuple(scanned_header[index] for index in descriptor_indexes), tuple(smiles_values), True)
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def inspect_selected_csvs(
|
|
181
|
+
main_path: str,
|
|
182
|
+
external_path: str = "",
|
|
183
|
+
*,
|
|
184
|
+
target_column: str = "",
|
|
185
|
+
name_column: str = "",
|
|
186
|
+
prediction_type: str = "",
|
|
187
|
+
ignored_columns: Iterable[str] = (),
|
|
188
|
+
) -> tuple[ResultInsight, ...]:
|
|
189
|
+
"""Inspect only selected CSV paths and return bounded, source-linked findings."""
|
|
190
|
+
ignored = {str(name).strip().casefold() for name in ignored_columns}
|
|
191
|
+
main = _profile_csv(Path(main_path), "Main", target_column, name_column, prediction_type, ignored) if main_path else None
|
|
192
|
+
external = _profile_csv(Path(external_path), "External", target_column, name_column, prediction_type, ignored) if external_path else None
|
|
193
|
+
profiles = tuple(profile for profile in (main, external) if profile is not None)
|
|
194
|
+
insights = [profile.insight for profile in profiles]
|
|
195
|
+
if main is not None and external is not None and main.inspected and external.inspected:
|
|
196
|
+
external_headers = set(external.descriptors)
|
|
197
|
+
absent = [name for name in main.descriptors if name not in external_headers]
|
|
198
|
+
if absent:
|
|
199
|
+
insight = external.insight
|
|
200
|
+
detail = "; ".join(f"missing descriptor column: {name[:80]}" for name in absent[:3])
|
|
201
|
+
if len(absent) > 3:
|
|
202
|
+
detail += f"; {len(absent) - 3} more required descriptor columns absent"
|
|
203
|
+
insights[1] = ResultInsight("", "", "input_csv", f"{insight.summary}; {detail}", insight.source)
|
|
204
|
+
if main.smiles and external.smiles:
|
|
205
|
+
main_smiles = set(main.smiles)
|
|
206
|
+
overlap = sum(value in main_smiles for value in external.smiles)
|
|
207
|
+
summary = (
|
|
208
|
+
f"Exact SMILES overlap in scanned rows: {overlap}/{len(external.smiles)} external SMILES "
|
|
209
|
+
"also occur in the main CSV; SMILES were not chemically canonicalized"
|
|
210
|
+
)
|
|
211
|
+
insights.append(ResultInsight("", "", "dataset_overlap", summary, f"{main.insight.source}, {external.insight.source}"))
|
|
212
|
+
return tuple(insights)
|