@@ -447,6 +447,9 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
447
447
/// If `is_fortran` is true, then
448
448
/// a fortran order array is created, otherwise a C-order array is created.
449
449
///
450
+ /// For elements with `DATA_TYPE == DataType::Object`, this will fill the array
451
+ /// valid pointers to objects of type `<class 'int'>` with value zero.
452
+ ///
450
453
/// See also [PyArray_Zeros](https://numpy.org/doc/stable/reference/c-api/array.html#c.PyArray_Zeros)
451
454
///
452
455
/// # Example
@@ -776,14 +779,9 @@ impl<T: Element> PyArray<T, Ix1> {
776
779
/// });
777
780
/// ```
778
781
pub fn from_exact_iter ( py : Python < ' _ > , iter : impl ExactSizeIterator < Item = T > ) -> & Self {
779
- // Use zero-initialized pointers for object arrays
780
- // so that partially initialized arrays can be dropped safely
781
- // in case the iterator implementation panics.
782
- let array = if T :: DATA_TYPE == DataType :: Object {
783
- Self :: zeros ( py, [ iter. len ( ) ] , false )
784
- } else {
785
- Self :: new ( py, [ iter. len ( ) ] , false )
786
- } ;
782
+ // NumPy will always zero-initialize object pointers,
783
+ // so the array can be dropped safely if the iterator panics.
784
+ let array = Self :: new ( py, [ iter. len ( ) ] , false ) ;
787
785
unsafe {
788
786
for ( i, item) in iter. enumerate ( ) {
789
787
* array. uget_mut ( [ i] ) = item;
@@ -811,14 +809,9 @@ impl<T: Element> PyArray<T, Ix1> {
811
809
let iter = iter. into_iter ( ) ;
812
810
let ( min_len, max_len) = iter. size_hint ( ) ;
813
811
let mut capacity = max_len. unwrap_or_else ( || min_len. max ( 512 / mem:: size_of :: < T > ( ) ) ) ;
814
- // Use zero-initialized pointers for object arrays
815
- // so that partially initialized arrays can be dropped safely
816
- // in case the iterator implementation panics.
817
- let array = if T :: DATA_TYPE == DataType :: Object {
818
- Self :: zeros ( py, [ capacity] , false )
819
- } else {
820
- Self :: new ( py, [ capacity] , false )
821
- } ;
812
+ // NumPy will always zero-initialize object pointers,
813
+ // so the array can be dropped safely if the iterator panics.
814
+ let array = Self :: new ( py, [ capacity] , false ) ;
822
815
let mut length = 0 ;
823
816
unsafe {
824
817
for ( i, item) in iter. enumerate ( ) {
0 commit comments