Skip to content

Commit f455222

Browse files
author
Bertrand MICHEL
committed
[dtype] Change comments and solutions format for test
1 parent 1400520 commit f455222

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

include/pybind11/numpy.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,12 +507,20 @@ class dtype : public object {
507507
return detail::array_descriptor_proxy(m_ptr)->names != nullptr;
508508
}
509509

510-
/// Single-character for dtype's kind (ex: float and double are 'f' or int and long int are 'i')
510+
/**
511+
* Single-character for dtype's kind
512+
* ex: float and double are 'f' or int and long int are 'i',
513+
* i.e. "float and double" could be "floating point types",
514+
* and "int and long" could be "integral types")
515+
*/
511516
char kind() const {
512517
return detail::array_descriptor_proxy(m_ptr)->kind;
513518
}
514519

515-
/// Single-character for dtype's type (ex: float is 'f' and double 'd')
520+
/** Single-character for dtype's type (ex: float is 'f' and double 'd').
521+
* NB: Following the Python API (i.e., dtype.char) is preferred here
522+
* rather than NumPy's internal C API (PyArray_Descr::type)
523+
*/
516524
char char_() const {
517525
return detail::array_descriptor_proxy(m_ptr)->type;
518526
}

tests/test_numpy_dtypes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ py::list test_dtype_kind() {
267267
return list;
268268
}
269269

270-
py::list test_dtype_type() {
270+
py::list test_dtype_char_() {
271271
py::list list;
272272
for (auto& dt : {
273273
py::dtype("bool8"), // bool
@@ -409,7 +409,7 @@ TEST_SUBMODULE(numpy_dtypes, m) {
409409
});
410410
m.def("test_dtype_ctors", &test_dtype_ctors);
411411
m.def("test_dtype_kind", &test_dtype_kind);
412-
m.def("test_dtype_type", &test_dtype_type);
412+
m.def("test_dtype_char_", &test_dtype_char_);
413413
m.def("test_dtype_methods", []() {
414414
py::list list;
415415
auto dt1 = py::dtype::of<int32_t>();

tests/test_numpy_dtypes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ def test_dtype(simple_dtype):
169169
np.zeros(1, m.trailing_padding_dtype())
170170
)
171171

172-
assert m.test_dtype_kind() == ["b"] + ["i"] * 3 + ["f"] * 3
173-
assert m.test_dtype_type() == ["?", "h", "i", "l", "f", "d", "g"]
172+
assert m.test_dtype_kind() == list("biiifff")
173+
assert m.test_dtype_char_() == list("?hilfdg")
174174

175175

176176
def test_recarray(simple_dtype, packed_dtype):

0 commit comments

Comments
 (0)