@@ -103,18 +103,18 @@ impl DictArray {
103103
104104 /// Build a new `DictArray` from its components, `codes` and `values`.
105105 ///
106- /// The codes must be unsigned integers, and may be nullable. Values can be any type, and
107- /// may also be nullable. This mirrors the nullability of the Arrow `DictionaryArray`.
106+ /// The codes must be integers, and may be nullable. Values can be any
107+ /// type, and may also be nullable. This mirrors the nullability of the Arrow `DictionaryArray`.
108108 ///
109109 /// # Errors
110110 ///
111- /// The `codes` **must** be unsigned integers, and the maximum code must be less than the length
111+ /// The `codes` **must** be integers, and the maximum code must be less than the length
112112 /// of the `values` array. Otherwise, this constructor returns an error.
113113 ///
114114 /// It is an error to provide a nullable `codes` with non-nullable `values`.
115115 pub fn try_new ( codes : ArrayRef , values : ArrayRef ) -> VortexResult < Self > {
116- if !codes. dtype ( ) . is_unsigned_int ( ) {
117- vortex_bail ! ( MismatchedTypes : "unsigned int" , codes. dtype( ) ) ;
116+ if !codes. dtype ( ) . is_int ( ) {
117+ vortex_bail ! ( MismatchedTypes : "int" , codes. dtype( ) ) ;
118118 }
119119
120120 Ok ( unsafe { Self :: new_unchecked ( codes, values) } )
@@ -194,7 +194,11 @@ impl DictArray {
194194 match codes_validity. bit_buffer ( ) {
195195 AllOr :: All => {
196196 match_each_integer_ptype ! ( codes_primitive. ptype( ) , |P | {
197- #[ allow( clippy:: cast_possible_truncation) ]
197+ #[ allow(
198+ clippy:: cast_possible_truncation,
199+ clippy:: cast_sign_loss,
200+ reason = "codes are non-negative indices; a negative signed code would wrap to a large usize and panic on the bounds-checked array index"
201+ ) ]
198202 for & code in codes_primitive. as_slice:: <P >( ) . iter( ) {
199203 values_vec[ code as usize ] = referenced_value;
200204 }
@@ -205,7 +209,11 @@ impl DictArray {
205209 match_each_integer_ptype ! ( codes_primitive. ptype( ) , |P | {
206210 let codes = codes_primitive. as_slice:: <P >( ) ;
207211
208- #[ allow( clippy:: cast_possible_truncation) ]
212+ #[ allow(
213+ clippy:: cast_possible_truncation,
214+ clippy:: cast_sign_loss,
215+ reason = "codes are non-negative indices; a negative signed code would wrap to a large usize and panic on the bounds-checked array index"
216+ ) ]
209217 buf. set_indices( ) . for_each( |idx| {
210218 values_vec[ codes[ idx] as usize ] = referenced_value;
211219 } )
0 commit comments