MCPcopy Create free account
hub / github.com/numpy/numpy / metastr_to_unicode

Function metastr_to_unicode

numpy/core/src/multiarray/datetime.c:1995–2038  ·  view source on GitHub ↗

* Return the datetime metadata as a Unicode object. * * Returns new reference, NULL on error. * * If 'skip_brackets' is true, skips the '[]'. * */

Source from the content-addressed store, hash-verified

1993 *
1994 */
1995NPY_NO_EXPORT PyObject *
1996metastr_to_unicode(PyArray_DatetimeMetaData *meta, int skip_brackets)
1997{
1998 int num;
1999 char const *basestr;
2000
2001 if (meta->base == NPY_FR_GENERIC) {
2002 /* Without brackets, give a string "generic" */
2003 if (skip_brackets) {
2004 return PyUnicode_FromString("generic");
2005 }
2006 /* But with brackets, return nothing */
2007 else {
2008 return PyUnicode_FromString("");
2009 }
2010 }
2011
2012 num = meta->num;
2013 if (meta->base >= 0 && meta->base < NPY_DATETIME_NUMUNITS) {
2014 basestr = _datetime_strings[meta->base];
2015 }
2016 else {
2017 PyErr_SetString(PyExc_RuntimeError,
2018 "NumPy datetime metadata is corrupted");
2019 return NULL;
2020 }
2021
2022 if (num == 1) {
2023 if (skip_brackets) {
2024 return PyUnicode_FromFormat("%s", basestr);
2025 }
2026 else {
2027 return PyUnicode_FromFormat("[%s]", basestr);
2028 }
2029 }
2030 else {
2031 if (skip_brackets) {
2032 return PyUnicode_FromFormat("%d%s", num, basestr);
2033 }
2034 else {
2035 return PyUnicode_FromFormat("[%d%s]", num, basestr);
2036 }
2037 }
2038}
2039
2040
2041/*

Calls

no outgoing calls

Tested by

no test coverage detected