Template Class duration_caster#
Defined in File pybind11_chrono_numpy.h
Class Documentation#
-
template<typename type>
class duration_caster# Class converts between std::chrono::durations and numpy timedelta64s.
Public Types
-
using days = std::chrono::duration<int_least32_t, std::ratio<86400>>#
signed 25 bits required by the standard.
Public Functions
-
inline bool load(handle src, bool)#
Cast from Python float, numpy timedelta, or datetime to std::chrono::nanoseconds.
- Parameters:
src – Handle to the Python object.
- Returns:
trueif the cast was successful,falseotherwise.
- PYBIND11_TYPE_CASTER (type, pybind11::detail::io_name("Union[float|numpy.timedelta64]", "numpy.timedelta64"))
Type caster to use float or numpy.timedelta64 as an input type, and numpy.timedelta64 as the output type.
Public Static Functions
-
static inline const std::chrono::duration<rep, period> &get_duration(const std::chrono::duration<rep, period> &src)#
If we get a C++ std::chrono::duration, just return it back.
- Parameters:
src – The input std::chrono::duration.
- Returns:
The input duration.
-
template<typename Clock>
static inline std::chrono::duration<rep, period> get_duration(const std::chrono::time_point<Clock, std::chrono::duration<rep, period>> &src)# If this is a time_point, get the time_since_epoch.
- Parameters:
src – The input std::chrono::time_point.
- Returns:
The input time_point cast to a duration via the time_since_epoch() method.
-
static inline handle cast(const type &src, return_value_policy, handle)#
Given a duration, return a Python object that represents it (a numpy timedelta64).
- Parameters:
src – Input type. We use get_duration to convert it to a C++ type.
- Returns:
A handle to the new Python object that represents the input src as a numpy timedelta64.
-
using days = std::chrono::duration<int_least32_t, std::ratio<86400>>#