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

Function _convert_from_str

numpy/core/src/multiarray/descriptor.c:1724–1884  ·  view source on GitHub ↗

Convert a bytestring specification into a dtype */

Source from the content-addressed store, hash-verified

1722
1723/** Convert a bytestring specification into a dtype */
1724static PyArray_Descr *
1725_convert_from_str(PyObject *obj, int align)
1726{
1727 /* Check for a string typecode. */
1728 Py_ssize_t len = 0;
1729 char const *type = PyUnicode_AsUTF8AndSize(obj, &len);
1730 if (type == NULL) {
1731 return NULL;
1732 }
1733
1734 /* Empty string is invalid */
1735 if (len == 0) {
1736 goto fail;
1737 }
1738
1739 /* check for commas present or first (or second) element a digit */
1740 if (_check_for_commastring(type, len)) {
1741 return _convert_from_commastring(obj, align);
1742 }
1743
1744 /* Process the endian character. '|' is replaced by '='*/
1745 char endian = '=';
1746 switch (type[0]) {
1747 case '>':
1748 case '<':
1749 case '=':
1750 endian = type[0];
1751 ++type;
1752 --len;
1753 break;
1754
1755 case '|':
1756 endian = '=';
1757 ++type;
1758 --len;
1759 break;
1760 }
1761
1762 /* Just an endian character is invalid */
1763 if (len == 0) {
1764 goto fail;
1765 }
1766
1767 /* Check for datetime format */
1768 if (is_datetime_typestr(type, len)) {
1769 PyArray_Descr *ret = parse_dtype_from_datetime_typestr(type, len);
1770 if (ret == NULL) {
1771 return NULL;
1772 }
1773 /* ret has byte order '=' at this point */
1774 if (!PyArray_ISNBO(endian)) {
1775 ret->byteorder = endian;
1776 }
1777 return ret;
1778 }
1779
1780 int check_num = NPY_NOTYPE + 10;
1781 int elsize = 0;

Callers 1

_convert_from_anyFunction · 0.85

Calls 6

_check_for_commastringFunction · 0.85
is_datetime_typestrFunction · 0.85
PyArray_TypestrConvertFunction · 0.85
_convert_from_anyFunction · 0.85

Tested by

no test coverage detected