Skip to content

Commit

Permalink
Drop deprecations introduced in version 0.17.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamreichold committed Feb 28, 2023
1 parent 0a99920 commit d58add3
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 83 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

- Unreleased
- Drop deprecated `PyArray::from_exact_iter` as it does not provide any benefits over `PyArray::from_iter`. ([#370](https://github.com/PyO3/rust-numpy/pull/370))

- v0.18.0
- Add conversions from and to datatypes provided by the [`nalgebra` crate](https://nalgebra.org/). ([#347](https://github.com/PyO3/rust-numpy/pull/347))
Expand Down
45 changes: 1 addition & 44 deletions benches/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ fn downcast_failure(bencher: &mut Bencher) {
});
});
}

struct Iter(Range<usize>);

impl Iterator for Iter {
Expand Down Expand Up @@ -84,50 +85,6 @@ fn from_iter_large(bencher: &mut Bencher) {
from_iter(bencher, 2_usize.pow(15));
}

struct ExactIter(Range<usize>);

impl Iterator for ExactIter {
type Item = usize;

fn next(&mut self) -> Option<Self::Item> {
self.0.next()
}

fn size_hint(&self) -> (usize, Option<usize>) {
self.0.size_hint()
}
}

impl ExactSizeIterator for ExactIter {
fn len(&self) -> usize {
self.0.len()
}
}

fn from_exact_iter(bencher: &mut Bencher, size: usize) {
iter_with_gil(bencher, |py| {
let iter = black_box(ExactIter(0..size));

#[allow(deprecated)]
PyArray1::from_exact_iter(py, iter);
});
}

#[bench]
fn from_exact_iter_small(bencher: &mut Bencher) {
from_exact_iter(bencher, 2_usize.pow(5));
}

#[bench]
fn from_exact_iter_medium(bencher: &mut Bencher) {
from_exact_iter(bencher, 2_usize.pow(10));
}

#[bench]
fn from_exact_iter_large(bencher: &mut Bencher) {
from_exact_iter(bencher, 2_usize.pow(15));
}

fn from_slice(bencher: &mut Bencher, size: usize) {
let vec = (0..size).collect::<Vec<_>>();

Expand Down
26 changes: 0 additions & 26 deletions src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1248,32 +1248,6 @@ impl<T: Element> PyArray<T, Ix1> {
vec.into_pyarray(py)
}

/// Construct a one-dimensional array from an [`ExactSizeIterator`].
///
/// # Example
///
/// ```
/// use numpy::PyArray;
/// use pyo3::Python;
///
/// Python::with_gil(|py| {
/// let pyarray = PyArray::from_exact_iter(py, [1, 2, 3, 4, 5].into_iter().copied());
/// assert_eq!(pyarray.readonly().as_slice().unwrap(), &[1, 2, 3, 4, 5]);
/// });
/// ```
#[deprecated(
since = "0.17.0",
note = "`from_exact_iter` is deprecated as it does not provide any benefit over `from_iter`."
)]
#[inline(always)]
pub fn from_exact_iter<I>(py: Python<'_>, iter: I) -> &Self
where
I: IntoIterator<Item = T>,
I::IntoIter: ExactSizeIterator,
{
Self::from_iter(py, iter)
}

/// Construct a one-dimensional array from an [`Iterator`].
///
/// If no reliable [`size_hint`][Iterator::size_hint] is available,
Expand Down
13 changes: 0 additions & 13 deletions tests/to_py.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,6 @@ fn long_iter_to_pyarray() {
});
}

#[test]
fn exact_iter_to_pyarray() {
Python::with_gil(|py| {
#[allow(deprecated)]
let arr = PyArray::from_exact_iter(py, 0_u32..512);

assert_eq!(
arr.readonly().as_slice().unwrap(),
(0_u32..512).collect::<Vec<_>>(),
);
});
}

#[test]
fn from_small_array() {
macro_rules! small_array_test {
Expand Down

0 comments on commit d58add3

Please sign in to comment.