Fix accidental loss-of-precision for to_datetime(str, unit=...) by QuLogic · Pull Request #57548 · pandas-dev/pandas (original) (raw)
As noted, cast_from_unit
takes an object
, so that doesn't seem to save anything. Here's the diff of the generated code when you add the type (vs having it commented out since that reduces line number changes in the diff):
--- untyped/pandas/_libs/tslib.pyx.c 2024-02-21 18:27:51.686387390 -0500 +++ typed/pandas/_libs/tslib.pyx.c 2024-02-21 18:24:14.824227898 -0500 @@ -25828,9 +25828,9 @@ int __pyx_v_is_raise; PyArrayObject *__pyx_v_iresult = 0; PyDateTime_TZInfo *__pyx_v_tz = 0;
- double __pyx_v_fval; PyObject *__pyx_v_result = NULL; PyObject *__pyx_v_val = NULL;
- double __pyx_v_fval; PyObject *__pyx_v_err = NULL; __Pyx_LocalBuf_ND __pyx_pybuffernd_iresult; __Pyx_Buffer __pyx_pybuffer_iresult; @@ -25919,14 +25919,14 @@
bint is_raise = errors == "raise"
ndarray[int64_t] iresult
tzinfo tz = None # <<<<<<<<<<<<<<
# double fval
double fval
- */ __Pyx_INCREF(Py_None); __pyx_v_tz = ((PyDateTime_TZInfo *)Py_None);
/* "pandas/_libs/tslib.pyx":280
# double fval
double fval
assert is_coerce or is_raise # <<<<<<<<<<<<<<
- @@ -32771,7 +32771,7 @@
ndarray[object] values,
str unit,
*/
- __pyx_tuple__37 = PyTuple_Pack(13, __pyx_n_s_values, __pyx_n_s_unit, __pyx_n_s_errors, __pyx_n_s_i, __pyx_n_s_n, __pyx_n_s_is_coerce, __pyx_n_s_is_raise, __pyx_n_s_iresult, __pyx_n_s_tz, __pyx_n_s_result, __pyx_n_s_val, __pyx_n_s_fval, __pyx_n_s_err); if (unlikely(!__pyx_tuple__37)) __PYX_ERR(0, 239, __pyx_L1_error)
- __pyx_tuple__37 = PyTuple_Pack(13, __pyx_n_s_values, __pyx_n_s_unit, __pyx_n_s_errors, __pyx_n_s_i, __pyx_n_s_n, __pyx_n_s_is_coerce, __pyx_n_s_is_raise, __pyx_n_s_iresult, __pyx_n_s_tz, __pyx_n_s_fval, __pyx_n_s_result, __pyx_n_s_val, __pyx_n_s_err); if (unlikely(!__pyx_tuple__37)) __PYX_ERR(0, 239, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__37); __Pyx_GIVEREF(__pyx_tuple__37); __pyx_codeobj__38 = (PyObject*)__Pyx_PyCode_New(3, 0, 0, 13, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__37, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_elliott_code_pandas_pandas, __pyx_n_s_array_with_unit_to_datetime, 239, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__38)) __PYX_ERR(0, 239, __pyx_L1_error)