Skip to content

Commit 0fd116d

Browse files
committed
Enable py::ellipsis tests on Python 2 and mention Ellipsis in the docs
1 parent 056f7e5 commit 0fd116d

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

docs/advanced/pycpp/numpy.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,8 @@ Ellipsis
371371
Python 3 provides a convenient ``...`` ellipsis notation that is often used to
372372
slice multidimensional arrays. For instance, the following snippet extracts the
373373
middle dimensions of a tensor with the first and last index set to zero.
374+
In Python 2, the syntactic sugar ``...`` is not available, but the singleton
375+
``Ellipsis`` (of type ``ellipsis``) can still be used directly.
374376

375377
.. code-block:: python
376378

tests/test_numpy_array.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,7 @@ TEST_SUBMODULE(numpy_array, sm) {
382382
return a;
383383
});
384384

385-
#if PY_MAJOR_VERSION >= 3
386-
sm.def("index_using_ellipsis", [](py::array a) {
387-
return a[py::make_tuple(0, py::ellipsis(), 0)];
388-
});
389-
#endif
385+
sm.def("index_using_ellipsis", [](py::array a) {
386+
return a[py::make_tuple(0, py::ellipsis(), 0)];
387+
});
390388
}

tests/test_numpy_array.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,6 @@ def test_array_create_and_resize(msg):
431431
assert(np.all(a == 42.))
432432

433433

434-
@pytest.unsupported_on_py2
435434
def test_index_using_ellipsis():
436435
a = m.index_using_ellipsis(np.zeros((5, 6, 7)))
437436
assert a.shape == (6,)

0 commit comments

Comments
 (0)