def add_newdoc_for_scalar_type(obj, fixed_aliases, doc): # note: `:field: value` is rST syntax which renders as field lists. o = getattr(_numerictypes, obj) character_code = dtype(o).char canonical_name_doc = ( "" if obj == o.__name__ else ":Canonical name: `numpy.{}`\n ".format(obj) ) alias_doc = "".join( ":Alias: `numpy.{}`\n ".format(alias) for alias in fixed_aliases ) alias_doc += "".join( ":Alias on this platform: `numpy.{}`: {}.\n ".format(alias, doc) for (alias_type, alias, doc) in possible_aliases if alias_type is o ) docstring = """ {doc} :Character code: ``'{character_code}'`` {canonical_name_doc}{alias_doc} """.format( doc=doc.strip(), character_code=character_code, canonical_name_doc=canonical_name_doc, alias_doc=alias_doc, ) add_newdoc("numpy.core.numerictypes", obj, docstring)
def add_newdoc_for_scalar_type(obj, fixed_aliases, doc): # note: `:field: value` is rST syntax which renders as field lists. o = getattr(_numerictypes, obj) character_code = dtype(o).char canonical_name_doc = "" if obj == o.__name__ else \ f":Canonical name: `numpy.{obj}`\n " if fixed_aliases: alias_doc = ''.join(f":Alias: `numpy.{alias}`\n " for alias in fixed_aliases) else: alias_doc = '' alias_doc += ''.join(f"{_doc_alias_string} `numpy.{alias}`: {doc}.\n " for (alias_type, alias, doc) in possible_aliases if alias_type is o) docstring = f""" {doc.strip()} :Character code: ``'{character_code}'`` {canonical_name_doc}{alias_doc} """ add_newdoc('numpy.core.numerictypes', obj, docstring)
""") add_newdoc_for_scalar_type('clongdouble', ['clongfloat', 'longcomplex'], """ Complex number type composed of two extended-precision floating-point numbers. """) add_newdoc_for_scalar_type('object_', [], """ Any Python object. """) # TODO: work out how to put this on the base class, np.floating for float_name in ('half', 'single', 'double', 'longdouble'): add_newdoc('numpy.core.numerictypes', float_name, ('as_integer_ratio', """ {ftype}.as_integer_ratio() -> (int, int) Return a pair of integers, whose ratio is exactly equal to the original floating point number, and with a positive denominator. Raise OverflowError on infinities and a ValueError on NaNs. >>> np.{ftype}(10.0).as_integer_ratio() (10, 1) >>> np.{ftype}(0.0).as_integer_ratio() (0, 1) >>> np.{ftype}(-.25).as_integer_ratio() (-1, 4) """.format(ftype=float_name)))
add_newdoc_for_scalar_type('timedelta64', [], """ A timedelta stored as a 64-bit integer. See :ref:`arrays.datetime` for more information. """) add_newdoc('numpy.core.numerictypes', "integer", ('is_integer', """ integer.is_integer() -> bool Return ``True`` if the number is finite with integral value. .. versionadded:: 1.22 Examples -------- >>> np.int64(-2).is_integer() True >>> np.uint32(5).is_integer() True """)) # TODO: work out how to put this on the base class, np.floating for float_name in ('half', 'single', 'double', 'longdouble'): add_newdoc('numpy.core.numerictypes', float_name, ('as_integer_ratio', """ {ftype}.as_integer_ratio() -> (int, int) Return a pair of integers, whose ratio is exactly equal to the original
""") add_newdoc_for_scalar_type( 'timedelta64', [], """ A timedelta stored as a 64-bit integer. See :ref:`arrays.datetime` for more information. """) add_newdoc('numpy.core.numerictypes', "integer", ('is_integer', """ integer.is_integer() -> bool Return ``True`` if the number is finite with integral value. .. versionadded:: 1.22 Examples -------- >>> np.int64(-2).is_integer() True >>> np.uint32(5).is_integer() True """)) # TODO: work out how to put this on the base class, np.floating for float_name in ('half', 'single', 'double', 'longdouble'): add_newdoc('numpy.core.numerictypes', float_name, ('as_integer_ratio', """ {ftype}.as_integer_ratio() -> (int, int) Return a pair of integers, whose ratio is exactly equal to the original floating point number, and with a positive denominator. Raise `OverflowError` on infinities and a `ValueError` on NaNs.