From 19e310688d0cb0365e37e4cf04b90515ab5f6026 Mon Sep 17 00:00:00 2001 From: Jeremy Leibs Date: Tue, 15 Oct 2024 17:00:36 -0400 Subject: [PATCH 1/3] Warn when selection only includes static data --- rerun_py/src/dataframe.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/rerun_py/src/dataframe.rs b/rerun_py/src/dataframe.rs index d6352aff90f6..34b3baa735bc 100644 --- a/rerun_py/src/dataframe.rs +++ b/rerun_py/src/dataframe.rs @@ -42,6 +42,16 @@ pub(crate) fn register(m: &Bound<'_, PyModule>) -> PyResult<()> { Ok(()) } +fn py_rerun_warn(msg: &str) -> PyResult<()> { + Python::with_gil(|py| { + let warning_type = PyModule::import_bound(py, "rerun")? + .getattr("error_utils")? + .getattr("RerunWarning")?; + PyErr::warn_bound(py, &warning_type, msg, 0)?; + Ok(()) + }) +} + /// Python binding for `IndexColumnDescriptor` #[pyclass(frozen, name = "IndexColumnDescriptor")] #[derive(Clone)] @@ -513,6 +523,18 @@ impl PyRecordingView { let query_handle = engine.query(query_expression); + let available_data_columns = query_handle + .view_contents() + .iter() + .filter(|c| matches!(c, ColumnDescriptor::Component(_))) + .collect::>(); + + if !available_data_columns.is_empty() + && available_data_columns.iter().all(|c| c.is_static()) + { + py_rerun_warn("RecordingView::select: contents only include static columns. No results will be returned. Either include non-static data or consider using `select_static()` instead.")?; + } + let schema = query_handle.schema(); let fields: Vec = schema.fields.iter().map(|f| f.clone().into()).collect(); From ada2f3579d35fafeb85df27458c6a7e4d7fc6f6b Mon Sep 17 00:00:00 2001 From: Jeremy Leibs Date: Tue, 15 Oct 2024 17:52:07 -0400 Subject: [PATCH 2/3] Don't warn when using_index_values is set --- rerun_py/src/dataframe.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rerun_py/src/dataframe.rs b/rerun_py/src/dataframe.rs index 34b3baa735bc..1e62658efb62 100644 --- a/rerun_py/src/dataframe.rs +++ b/rerun_py/src/dataframe.rs @@ -529,7 +529,8 @@ impl PyRecordingView { .filter(|c| matches!(c, ColumnDescriptor::Component(_))) .collect::>(); - if !available_data_columns.is_empty() + if self.query_expression.using_index_values.is_none() + && !available_data_columns.is_empty() && available_data_columns.iter().all(|c| c.is_static()) { py_rerun_warn("RecordingView::select: contents only include static columns. No results will be returned. Either include non-static data or consider using `select_static()` instead.")?; From 19b2f95ec86f194798302743ee3c76496062a7fe Mon Sep 17 00:00:00 2001 From: Jeremy Leibs Date: Tue, 15 Oct 2024 20:17:56 -0400 Subject: [PATCH 3/3] Improve error logic --- rerun_py/src/dataframe.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/rerun_py/src/dataframe.rs b/rerun_py/src/dataframe.rs index 1e62658efb62..4a6e9650a3ab 100644 --- a/rerun_py/src/dataframe.rs +++ b/rerun_py/src/dataframe.rs @@ -523,17 +523,35 @@ impl PyRecordingView { let query_handle = engine.query(query_expression); + // If the only contents found are static, we might need to warn the user since + // this means we won't naturally have any rows in the result. let available_data_columns = query_handle .view_contents() .iter() .filter(|c| matches!(c, ColumnDescriptor::Component(_))) .collect::>(); + // We only consider all contents static if there at least some columns + let all_contents_are_static = !available_data_columns.is_empty() + && available_data_columns.iter().all(|c| c.is_static()); + + // Additionally, we only want to warn if the user actually tried to select some + // of the static columns. Otherwise the fact that there are no results shouldn't + // be surprising. + let selected_data_columns = query_handle + .selected_contents() + .iter() + .map(|(_, col)| col) + .filter(|c| matches!(c, ColumnDescriptor::Component(_))) + .collect::>(); + + let any_selected_data_is_static = selected_data_columns.iter().any(|c| c.is_static()); + if self.query_expression.using_index_values.is_none() - && !available_data_columns.is_empty() - && available_data_columns.iter().all(|c| c.is_static()) + && all_contents_are_static + && any_selected_data_is_static { - py_rerun_warn("RecordingView::select: contents only include static columns. No results will be returned. Either include non-static data or consider using `select_static()` instead.")?; + py_rerun_warn("RecordingView::select: tried to select static data, but no non-static contents generated an index value on this timeline. No results will be returned. Either include non-static data or consider using `select_static()` instead.")?; } let schema = query_handle.schema();