You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let message = ifletOk(arr) = obj.downcast::<PyUntypedArray>(){
27
+
let ndim = arr.ndim();
28
+
if ndim != 1{
29
+
format!("'{name}' is a {ndim}-d array, only 1-d arrays are supported.")
30
+
}else{
31
+
let dtype = match arr.dtype().str(){
32
+
Ok(s) => s,
33
+
Err(err) => return err.into(),
34
+
};
35
+
format!("'{name}' has dtype {dtype}, but only float32 and float64 are supported.")
36
+
}
37
+
}else{
38
+
let tp = match obj.get_type().name(){
39
+
Ok(s) => s,
40
+
Err(err) => return err.into(),
41
+
};
42
+
format!(
43
+
"'{name}' has type '{tp}', float32 or float64 1-d numpy array was supported. Try to cast with np.asarray."
44
+
)
45
+
};
46
+
Exception::TypeError(message)
47
+
}
48
+
25
49
pub(crate)fnextract_matched_array<'py,T>(
26
50
y_name:&'staticstr,
27
51
y:Bound<'py,PyAny>,
@@ -39,43 +63,37 @@ where
39
63
Ok(y)
40
64
}else{
41
65
Err(Exception::ValueError(format!(
42
-
"Mismatched length ({}: {}, {}: {})",
43
-
y_name,
44
-
y.len(),
66
+
"Mismatched lengths: '{}': {}, '{}': {}",
45
67
x_name,
46
68
x.len(),
69
+
y_name,
70
+
y.len(),
47
71
)))
48
72
}
49
73
}else{
50
74
Ok(y)
51
75
}
52
76
}else{
53
-
let y_type = y
54
-
.get_type()
55
-
.name()
56
-
.map(|name| {
57
-
if name == "ndarray"{
58
-
format!(
59
-
"ndarray[{}]",
60
-
y.getattr("dtype")
61
-
.map(|dtype| dtype
62
-
.getattr("name")
63
-
.map(|p| p.to_string())
64
-
.unwrap_or("unknown".into()))
65
-
.unwrap_or("unknown".into())
66
-
)
67
-
}else{
68
-
name.to_string()
69
-
}
70
-
})
71
-
.unwrap_or("unknown".into());
72
-
Err(Exception::TypeError(format!(
73
-
"Mismatched types ({}: np.ndarray[{}], {}: {})",
74
-
x_name,
75
-
T::dtype_name(),
76
-
y_name,
77
-
y_type
78
-
)))
77
+
let error_message = ifletOk(y_arr) = y.downcast::<PyUntypedArray>(){
78
+
if y_arr.ndim() != 1{
79
+
format!(
80
+
"'{}' is a {}-d array, only 1-d arrays are supported.",
81
+
y_name,
82
+
y_arr.ndim()
83
+
)
84
+
}else{
85
+
format!(
86
+
"Mismatched dtypes: '{}': {}, '{}': {}",
87
+
x_name,
88
+
x.dtype().str()?,
89
+
y_name,
90
+
y_arr.dtype().str()?
91
+
)
92
+
}
93
+
}else{
94
+
format!("'{y_name}' must be a numpy array of the same shape and dtype as '{x_name}', '{x_name}' has type 'np.ndarray[{x_dtype}]', '{y_name}' has type '{y_type}')", y_type=y.get_type().name()?, x_dtype=T::dtype_name())
0 commit comments