diff --git a/pylace/src/lib.rs b/pylace/src/lib.rs index c53e43dd..30930436 100644 --- a/pylace/src/lib.rs +++ b/pylace/src/lib.rs @@ -1179,7 +1179,17 @@ impl CoreEngine { Ok(()) } - /// Remove Rows at the given indices + /// Remove Rows at the given indices. + /// + /// + /// Example + /// ------- + /// + /// >>> import lace + /// >>> engine = lace.Engine('animals.rp') + /// >>> removed = engine.remove_rows(["wolf", "ox"]) + /// >>> removed["index"] + /// fn remove_rows(&mut self, rows: &PyList) -> PyResult<PyDataFrame> { let remove: Vec<String> = rows .into_iter() diff --git a/pylace/src/metadata.rs b/pylace/src/metadata.rs index 1706e77a..e137608d 100644 --- a/pylace/src/metadata.rs +++ b/pylace/src/metadata.rs @@ -668,6 +668,19 @@ impl Codebook { Ok(()) } } + + fn like(&self, new_data: PyDataFrame) -> PyResult<Self> { + let index: Vec<String> = ["id", "ID", "index", "INDEX"].into_iter().map(|name| + new_data.0.column(name) + ).find(|x| x.is_ok()).ok_or_else(|| PyValueError::new_err("No index column: convention for index is ID or INDEX, in upper or lower case."))? + .expect("The value has already been checked") + .str().map_err(to_pyerr)?.into_iter().flatten().map(|x| x.to_string()).collect(); + + Ok(Self(lace::codebook::Codebook { + row_names: RowNameList::try_from(index).map_err(to_pyerr)?, + ..self.0.clone() + })) + } } #[pyfunction]