Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
magbak committed Dec 19, 2024
1 parent 3a1826e commit a0563f2
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 35 deletions.
8 changes: 2 additions & 6 deletions lib/maplib/src/mapping/expansion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,12 +796,8 @@ fn create_remapped(
let mut new_unique_subsets = vec![];
if let Some(le) = &instance.list_expander {
for e in &to_expand {
if let Some((k, v)) = new_dynamic_columns.remove_entry(*e) {
if let MappingColumnType::Nested(v) = v {
new_dynamic_columns.insert(k, *v);
} else {
panic!("This situation should never arise")
}
if let Some((k, MappingColumnType::Nested(v))) = new_dynamic_columns.remove_entry(*e) {
new_dynamic_columns.insert(k, *v);
} else {
panic!("This situation should never arise")
}
Expand Down
2 changes: 1 addition & 1 deletion lib/query_processing/src/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ pub fn exists(
pub fn func_expression(
mut solution_mappings: SolutionMappings,
func: &Function,
args: &Vec<Expression>,
args: &[Expression],
args_contexts: HashMap<usize, Context>,
outer_context: &Context,
) -> Result<SolutionMappings, QueryProcessingError> {
Expand Down
4 changes: 2 additions & 2 deletions lib/query_processing/src/graph_patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub fn filter(

pub fn prepare_group_by(
mut solution_mappings: SolutionMappings,
variables: &Vec<Variable>,
variables: &[Variable],
) -> (SolutionMappings, Vec<Expr>, Option<String>) {
let by: Vec<Expr>;
let dummy_varname = if variables.is_empty() {
Expand Down Expand Up @@ -202,7 +202,7 @@ pub fn minus(

pub fn order_by(
solution_mappings: SolutionMappings,
columns: &Vec<String>,
columns: &[String],
asc_ordering: Vec<bool>,
) -> Result<SolutionMappings, QueryProcessingError> {
if columns.is_empty() {
Expand Down
4 changes: 3 additions & 1 deletion lib/representation/src/multitype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,8 @@ pub fn known_convert_lf_multicol_to_single(
lf
}

pub fn explode_multicols<'a>(
#[allow(clippy::type_complexity)]
pub fn explode_multicols(
mut mappings: LazyFrame,
rdf_node_types: &HashMap<String, RDFNodeType>,
) -> (LazyFrame, HashMap<String, (Vec<String>, Vec<String>)>) {
Expand Down Expand Up @@ -930,6 +931,7 @@ pub fn unique_workaround(
lf
}

#[allow(clippy::type_complexity)]
pub fn group_by_workaround(
lf: LazyFrame,
rdf_node_types: &HashMap<String, RDFNodeType>,
Expand Down
6 changes: 2 additions & 4 deletions lib/representation/src/polars_to_rdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,8 @@ fn column_as_terms(column: &Column, t: &RDFNodeType) -> Vec<Option<Term>> {
for _ in 0..height {
let mut use_term = None;
for iter in iters.iter_mut() {
if let Some(term) = iter.next() {
if let Some(term) = term {
use_term = Some(term);
}
if let Some(Some(term)) = iter.next() {
use_term = Some(term);
}
}
final_terms.push(use_term);
Expand Down
1 change: 1 addition & 0 deletions lib/representation/src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ pub struct PyLiteral {
#[pymethods]
impl PyLiteral {
#[new]
#[pyo3(signature = (value, data_type=None, language=None))]
pub fn new(value: String, data_type: Option<PyIRI>, language: Option<String>) -> Self {
let data_type_iri = if let Some(data_type) = data_type {
Some(data_type.iri)
Expand Down
16 changes: 6 additions & 10 deletions lib/templates/src/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,18 +278,14 @@ fn lub(
left: &PType,
right: &PType,
) -> Result<PType, TemplateError> {
if left == right {
return Ok(left.clone());
} else if left.is_iri() && right.is_iri() {
if left == right || left.is_iri() && right.is_iri() {
return Ok(left.clone());
} else if let (PType::Basic(left_basic), PType::Basic(right_basic)) = (left, right) {
if left_basic.as_ref() == rdfs::RESOURCE {
return Ok(left.clone());
} else if right_basic.as_ref() == rdfs::RESOURCE {
return Ok(left.clone());
} else if is_literal_subtype(left_basic, right_basic) {
return Ok(left.clone());
} else if is_literal_subtype(right_basic, left_basic) {
if left_basic.as_ref() == rdfs::RESOURCE
|| right_basic.as_ref() == rdfs::RESOURCE
|| is_literal_subtype(left_basic, right_basic)
|| is_literal_subtype(right_basic, left_basic)
{
return Ok(left.clone());
} else {
// Returns error
Expand Down
6 changes: 6 additions & 0 deletions lib/templates/src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct PyParameter {
#[pymethods]
impl PyParameter {
#[new]
#[pyo3(signature = (variable, optional=None, allow_blank=None, rdf_type=None, default_value=None))]
pub fn new<'py>(
variable: PyVariable,
optional: Option<bool>,
Expand Down Expand Up @@ -204,6 +205,7 @@ pub struct PyArgument {
#[pymethods]
impl PyArgument {
#[new]
#[pyo3(signature = (term, list_expand=None))]
pub fn new(term: &Bound<'_, PyAny>, list_expand: Option<bool>) -> PyResult<Self> {
let list_expand = list_expand.unwrap_or(false);
let term = if let Ok(r) = term.extract::<PyVariable>() {
Expand Down Expand Up @@ -246,6 +248,7 @@ pub struct PyInstance {
#[pymethods]
impl PyInstance {
#[new]
#[pyo3(signature = (iri, arguments, list_expander=None))]
pub fn new(
iri: PyIRI,
arguments: Vec<Bound<'_, PyAny>>,
Expand Down Expand Up @@ -292,6 +295,7 @@ pub struct PyTemplate {
#[pymethods]
impl PyTemplate {
#[new]
#[pyo3(signature = (iri, parameters, instances, prefixed_iri=None))]
pub fn new<'py>(
iri: PyIRI,
parameters: Vec<Bound<'py, PyAny>>,
Expand Down Expand Up @@ -329,6 +333,7 @@ impl PyTemplate {
Ok(PyTemplate { template })
}

#[pyo3(signature = (arguments, list_expander=None))]
fn instance(
&self,
arguments: Vec<Bound<'_, PyAny>>,
Expand Down Expand Up @@ -398,6 +403,7 @@ impl PyTemplate {
}

#[pyfunction(name = "Triple")]
#[pyo3(signature = (subject, predicate, object, list_expander=None))]
pub fn py_triple<'py>(
subject: Bound<'py, PyAny>,
predicate: Bound<'py, PyAny>,
Expand Down
4 changes: 1 addition & 3 deletions lib/templates/src/subtypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ const OWL_RATIONAL: &str = "http://www.w3.org/2002/07/owl#rational";
pub fn is_literal_subtype(s: &NamedNode, t: &NamedNode) -> bool {
if !ptype_is_possibly_literal(s) || !ptype_is_possibly_literal(t) {
false
} else if s == t {
true
} else if t.as_ref() == rdfs::LITERAL {
} else if s == t || t.as_ref() == rdfs::LITERAL {
true
} else if t.as_str() == OWL_REAL {
owl_real_subtype(s)
Expand Down
1 change: 1 addition & 0 deletions lib/triplestore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ impl Triplestore {
}
}
}

fn subtract_from_transient(
&mut self,
triples_df: Vec<TripleDF>,
Expand Down
3 changes: 3 additions & 0 deletions lib/triplestore/src/query_solutions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub fn query_select(
df_as_result(df, &types)
}

#[allow(clippy::too_many_arguments)]
#[allow(clippy::type_complexity)]
pub fn get_seven_query_solutions(
query_solution: Vec<Option<Term>>,
variables: &[Variable],
Expand Down Expand Up @@ -78,6 +80,7 @@ pub fn get_seven_query_solutions(
(s1, s2, s3, s4, s5, s6, s7)
}

#[allow(clippy::type_complexity)]
pub fn get_five_query_solutions(
query_solution: Vec<Option<Term>>,
variables: &[Variable],
Expand Down
2 changes: 1 addition & 1 deletion lib/triplestore/src/sparql/lazy_graph_patterns/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl Triplestore {
pub(crate) fn lazy_group(
&self,
inner: &GraphPattern,
variables: &Vec<Variable>,
variables: &[Variable],
aggregates: &[(Variable, AggregateExpression)],
solution_mapping: Option<SolutionMappings>,
context: &Context,
Expand Down
1 change: 1 addition & 0 deletions lib/triplestore/src/sparql/lazy_graph_patterns/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ impl U32DataFrameCreator {
}
}

#[allow(clippy::type_complexity)]
pub fn create_u32_dfs(
self,
) -> Result<
Expand Down
10 changes: 3 additions & 7 deletions lib/triplestore/src/triples_write/serializers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,9 @@ pub(super) fn string_serializer<'a, Iter: Send + 'a>(
let Some(s) = f(iter) else {
return;
};
let mut chars = s.chars();
loop {
if let Some(c) = chars.next() {
write_escaped_char(c, buf);
} else {
break;
}
let chars = s.chars();
for c in chars {
write_escaped_char(c, buf);
}
buf.push(QUOTE_CHAR);
};
Expand Down
18 changes: 18 additions & 0 deletions py_maplib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ type ParametersType<'a> = HashMap<String, (Bound<'a, PyAny>, HashMap<String, PyR
#[pymethods]
impl PyMapping {
#[new]
#[pyo3(signature = (documents=None, caching_folder=None))]
fn new(
documents: Option<&Bound<'_, PyAny>>,
caching_folder: Option<&Bound<'_, PyAny>>,
Expand Down Expand Up @@ -169,6 +170,7 @@ impl PyMapping {
}
}

#[pyo3(signature = (template, df=None, unique_subset=None, graph=None, types=None))]
fn expand(
&mut self,
template: &Bound<'_, PyAny>,
Expand Down Expand Up @@ -238,6 +240,7 @@ impl PyMapping {
Ok(None)
}

#[pyo3(signature = (df, primary_key_column, template_prefix=None, predicate_uri_prefix=None, graph=None))]
fn expand_default(
&mut self,
df: &Bound<'_, PyAny>,
Expand Down Expand Up @@ -268,6 +271,7 @@ impl PyMapping {
}

#[allow(clippy::too_many_arguments)]
#[pyo3(signature = (query, parameters=None, include_datatypes=None, native_dataframe=None, graph=None, streaming=None, return_json=None))]
fn query(
&mut self,
py: Python<'_>,
Expand Down Expand Up @@ -299,6 +303,7 @@ impl PyMapping {
)
}

#[pyo3(signature = (graph=None))]
fn create_index(&mut self, graph: Option<String>) -> PyResult<()> {
let graph = parse_optional_graph(graph)?;
self.inner
Expand All @@ -307,6 +312,7 @@ impl PyMapping {
Ok(())
}

#[pyo3(signature = (shape_graph, include_details=None, include_conforms=None, include_shape_graph=None, streaming=None))]
fn validate(
&mut self,
shape_graph: String,
Expand Down Expand Up @@ -339,6 +345,7 @@ impl PyMapping {
Ok(PyValidationReport::new(report, shape_graph_triplestore))
}

#[pyo3(signature = (query, parameters=None, transient=None, streaming=None, source_graph=None, target_graph=None))]
fn insert(
&mut self,
query: String,
Expand Down Expand Up @@ -373,6 +380,7 @@ impl PyMapping {
Ok(())
}

#[pyo3(signature = (query, parameters=None, transient=None, streaming=None, source_graph=None, target_graph=None))]
fn insert_sprout(
&mut self,
query: String,
Expand Down Expand Up @@ -412,6 +420,7 @@ impl PyMapping {
}

#[allow(clippy::too_many_arguments)]
#[pyo3(signature = (file_path, format=None, base_iri=None, transient=None, parallel=None, checked=None, deduplicate=None, graph=None, replace_graph=None))]
fn read_triples(
&mut self,
file_path: &Bound<'_, PyAny>,
Expand Down Expand Up @@ -445,6 +454,7 @@ impl PyMapping {
}

#[allow(clippy::too_many_arguments)]
#[pyo3(signature = (s, format, base_iri=None, transient=None, parallel=None, checked=None, deduplicate=None, graph=None, replace_graph=None))]
fn read_triples_string(
&mut self,
s: &str,
Expand Down Expand Up @@ -474,6 +484,8 @@ impl PyMapping {
.map_err(PyMaplibError::from)?;
Ok(())
}

#[pyo3(signature = (file_path, graph=None))]
fn write_ntriples(
&mut self,
file_path: &Bound<'_, PyAny>,
Expand All @@ -483,6 +495,7 @@ impl PyMapping {
self.write_triples(file_path, Some("ntriples".to_string()), graph)
}

#[pyo3(signature = (file_path, format=None, graph=None))]
fn write_triples(
&mut self,
file_path: &Bound<'_, PyAny>,
Expand All @@ -505,11 +518,13 @@ impl PyMapping {
Ok(())
}

#[pyo3(signature = (graph=None))]
fn write_ntriples_string(&mut self, graph: Option<String>) -> PyResult<String> {
warn!("use write_triples_string with format=\"ntriples\" instead");
self.write_triples_string(Some("ntriples".to_string()), graph)
}

#[pyo3(signature = (format=None, graph=None))]
fn write_triples_string(
&mut self,
format: Option<String>,
Expand All @@ -526,6 +541,7 @@ impl PyMapping {
Ok(String::from_utf8(out).unwrap())
}

#[pyo3(signature = (folder_path, graph=None))]
fn write_native_parquet(
&mut self,
folder_path: &Bound<'_, PyAny>,
Expand All @@ -539,6 +555,7 @@ impl PyMapping {
Ok(())
}

#[pyo3(signature = (graph=None))]
fn get_predicate_iris(&mut self, graph: Option<String>) -> PyResult<Vec<PyIRI>> {
let graph = parse_optional_graph(graph)?;
let nns = self
Expand All @@ -548,6 +565,7 @@ impl PyMapping {
Ok(nns.into_iter().map(PyIRI::from).collect())
}

#[pyo3(signature = (iri, graph=None))]
fn get_predicate(
&mut self,
py: Python<'_>,
Expand Down
2 changes: 2 additions & 0 deletions py_maplib/src/shacl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ impl PyValidationReport {
self.inner.conforms
}

#[pyo3(signature = (native_dataframe=None, include_datatypes=None))]
pub fn results(
&self,
native_dataframe: Option<bool>,
Expand All @@ -54,6 +55,7 @@ impl PyValidationReport {
Ok(report)
}

#[pyo3(signature = (native_dataframe=None, include_datatypes=None))]
pub fn details(
&self,
native_dataframe: Option<bool>,
Expand Down

0 comments on commit a0563f2

Please sign in to comment.