mirror of
https://github.com/pybind/pybind11.git
synced 2025-01-31 15:20:34 +00:00
chore: simplify numpy dtype ctor (#3869)
* Simplify numpy dtype ctor * Simplify c_str ctor * Remove compat macro for str in numpy
This commit is contained in:
parent
45164c1fcb
commit
3829b7624c
@ -540,18 +540,16 @@ public:
|
||||
PYBIND11_OBJECT_DEFAULT(dtype, object, detail::npy_api::get().PyArrayDescr_Check_);
|
||||
|
||||
explicit dtype(const buffer_info &info) {
|
||||
dtype descr(_dtype_from_pep3118()(PYBIND11_STR_TYPE(info.format)));
|
||||
dtype descr(_dtype_from_pep3118()(pybind11::str(info.format)));
|
||||
// If info.itemsize == 0, use the value calculated from the format string
|
||||
m_ptr = descr.strip_padding(info.itemsize != 0 ? info.itemsize : descr.itemsize())
|
||||
.release()
|
||||
.ptr();
|
||||
}
|
||||
|
||||
explicit dtype(const std::string &format) {
|
||||
m_ptr = from_args(pybind11::str(format)).release().ptr();
|
||||
}
|
||||
explicit dtype(const std::string &format) : dtype(from_args(pybind11::str(format))) {}
|
||||
|
||||
explicit dtype(const char *format) : dtype(std::string(format)) {}
|
||||
explicit dtype(const char *format) : dtype(from_args(pybind11::str(format))) {}
|
||||
|
||||
dtype(list names, list formats, list offsets, ssize_t itemsize) {
|
||||
dict args;
|
||||
@ -638,7 +636,7 @@ private:
|
||||
}
|
||||
|
||||
struct field_descr {
|
||||
PYBIND11_STR_TYPE name;
|
||||
pybind11::str name;
|
||||
object format;
|
||||
pybind11::int_ offset;
|
||||
};
|
||||
@ -653,7 +651,7 @@ private:
|
||||
continue;
|
||||
}
|
||||
field_descriptors.push_back(
|
||||
{(PYBIND11_STR_TYPE) name, format.strip_padding(format.itemsize()), offset});
|
||||
{(pybind11::str) name, format.strip_padding(format.itemsize()), offset});
|
||||
}
|
||||
|
||||
std::sort(field_descriptors.begin(),
|
||||
@ -1359,7 +1357,7 @@ PYBIND11_NOINLINE void register_structured_dtype(any_container<field_descriptor>
|
||||
pybind11_fail(std::string("NumPy: unsupported field dtype: `") + field.name + "` @ "
|
||||
+ tinfo.name());
|
||||
}
|
||||
names.append(PYBIND11_STR_TYPE(field.name));
|
||||
names.append(pybind11::str(field.name));
|
||||
formats.append(field.descr);
|
||||
offsets.append(pybind11::int_(field.offset));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user