DataSources can be local files or remote files/URLs. The files may
also be compressed or uncompressed. DataSource hides some of the
low-level details of downloading the file, allowing you to simply pass
in a valid file path (or URL) and obtain a file object.
Parameters:
destpath (str or None, optional) – Path to the directory where the source file gets downloaded to for
use. If destpath is None, a temporary directory will be created.
The default path is the current directory.
Notes
URLs require a scheme string (http://) to be used, without it they
will fail:
Return absolute path of file in the DataSource directory.
If path is an URL, then abspath will return either the location
the file exists locally or the location it would exist when opened
using the open method.
Parameters:
path (str) – Can be a local file or a remote URL.
Returns:
out – Complete path, including the DataSource destination directory.
a remote URL that has been downloaded and stored locally in the
DataSource directory.
a remote URL that has not been downloaded, but is valid and
accessible.
Parameters:
path (str) – Can be a local file or a remote URL.
Returns:
out – True if path exists.
Return type:
bool
Notes
When path is an URL, exists will return True if it’s either
stored locally in the DataSource directory, or is a valid remote
URL. DataSource does not discriminate between the two, the file
is accessible if it exists in either location.
If path is an URL, it will be downloaded, stored in the
DataSource directory and opened from there.
Parameters:
path (str) – Local file path or URL to open.
mode ({'r', 'w', 'a'}, optional) – Mode to open path. Mode ‘r’ for reading, ‘w’ for writing,
‘a’ to append. Available modes depend on the type of object
specified by path. Default is ‘r’.
encoding ({None, str}, optional) – Open text file with given encoding. The default encoding will be
what io.open uses.
newline ({None, str}, optional) – Newline to use when reading text file.
The bool_ type is not a subclass of the int_ type
(the bool_ is not even a number type). This is different
than Python’s default implementation of bool as a
sub-class of int.
This is raised whenever the maximum number of candidate solutions
to consider specified by the max_work parameter is exceeded.
Assigning a finite number to max_work may have caused the operation
to fail.
The bool_ type is not a subclass of the int_ type
(the bool_ is not even a number type). This is different
than Python’s default implementation of bool as a
sub-class of int.
If a tuple, then the first element is interpreted as an attribute of
obj and the second as the docstring to apply - (method,docstring)
If a list, then each element of the list should be a tuple of length
two - [(method1,docstring1),(method2,docstring2),...]
warn_on_python (bool) – If True, the default, emit UserWarning if this is used to attach
documentation to a pure-python object.
Notes
This routine never raises an error if the docstring can’t be written, but
will raise an error if the object being documented does not exist.
This routine cannot modify read-only docstrings, as appear
in new-style classes or built-in functions. Because this
routine never raises an error the caller must check manually
that the docstrings were changed.
Since this function grabs the char* from a c-level str object and puts
it into the tp_doc slot of the type of obj, it violates a number of
C-API best-practices, by:
modifying a PyTypeObject after calling PyType_Ready
calling Py_INCREF on the str and losing the reference, so the str
will never be released
Return the binary representation of the input number as a string.
For negative numbers, if width is not given, a minus sign is added to the
front. If width is given, the two’s complement of the number is
returned, with respect to that width.
In a two’s-complement system negative numbers are represented by the two’s
complement of the absolute value. This is the most common method of
representing signed integers on computers [1]_. A N-bit two’s-complement
system can represent every integer in the range
\(-2^{N-1}\) to \(+2^{N-1}-1\).
Parameters:
num (int) – Only an integer decimal number can be used.
width (int, optional) –
The length of the returned string if num is positive, or the length
of the two’s complement if num is negative, provided that width is
at least a sufficient number of bits for num to be represented in the
designated form.
If the width value is insufficient, it will be ignored, and num will
be returned in binary (num > 0) or two’s complement (num < 0) form
with its width equal to the minimum number of bits needed to represent
the number in the designated form. This behavior is deprecated and will
later raise an error.
Deprecated since version 1.12.0.
Returns:
bin – Binary representation of num or two’s complement of num.
The bool_ type is not a subclass of the int_ type
(the bool_ is not even a number type). This is different
than Python’s default implementation of bool as a
sub-class of int.
Issues a DeprecationWarning, adds warning to old_name’s
docstring, rebinds old_name.__name__ and returns the new
function object.
This function may also be used as a decorator.
Parameters:
func (function) – The function to be deprecated.
old_name (str, optional) – The name of the function to be deprecated. Default is None, in
which case the name of func is used.
new_name (str, optional) – The new name for the function. Default is None, in which case the
deprecation message is that old_name is deprecated. If given, the
deprecation message is that old_name is deprecated and new_name
should be used instead.
message (str, optional) – Additional explanation of the deprecation. Displayed in the
docstring after the warning.
Returns:
old_func – The deprecated function.
Return type:
function
Examples
Note that olduint returns a value after printing Deprecation
Warning:
>>> olduint=np.deprecate(np.uint)DeprecationWarning: `uint64` is deprecated! # may vary>>> olduint(6)6
Deprecates a function and includes the deprecation in its docstring.
This function is used as a decorator. It returns an object that can be
used to issue a DeprecationWarning, by passing the to-be decorated
function as argument, this adds warning to the to-be decorated function’s
docstring and returns the new function object.
device (object) – Device to write message. If None, defaults to sys.stdout which is
very similar to print. device needs to have write() and
flush() methods.
linefeed (bool, optional) – Option whether to print a line feed or not. Defaults to True.
Raises:
AttributeError – If device does not have a write() or flush() method.
Examples
Besides sys.stdout, a file-like object can also be used as it has
both required methods:
>>> fromioimportStringIO>>> buf=StringIO()>>> np.disp(u'"Display" in a file',device=buf)>>> buf.getvalue()'"Display" in a file\n'
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.
Returns the dtype for which finfo returns information. For complex
input, the returned dtype is the associated float* dtype for its
real and complex components.
The difference between 1.0 and the next smallest representable float
larger than 1.0. For example, for 64-bit binary floats in the IEEE-754
standard, eps=2**-52, approximately 2.22e-16.
The difference between 1.0 and the next smallest representable float
less than 1.0. For example, for 64-bit binary floats in the IEEE-754
standard, epsneg=2**-53, approximately 1.11e-16.
The distance between a value and the nearest adjacent number
nextafter
The next floating point value after x1 towards x2
Notes
For developers of NumPy: do not instantiate this at the module level.
The initial calculation of these parameters is expensive and negatively
impacts import times. These objects are cached, so calling finfo()
repeatedly inside your functions is not a problem.
Note that smallest_normal is not actually the smallest positive
representable value in a NumPy floating point type. As in the IEEE-754
standard [1]_, NumPy floating point types make use of subnormal numbers to
fill the gap between 0 and smallest_normal. However, subnormal numbers
may have significantly reduced precision [2].
This function can also be used for complex data types as well. If used,
the output will be the same as the corresponding real float type
(e.g. numpy.finfo(numpy.csingle) is the same as numpy.finfo(numpy.single)).
However, the output is true for the real and imaginary components.
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.
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.
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.
Format a floating-point scalar as a decimal string in positional notation.
Provides control over rounding, trimming and padding. Uses and assumes
IEEE unbiased rounding. Uses the “Dragon4” algorithm.
Parameters:
x (python float or numpy floating scalar) – Value to format.
precision (non-negative integer or None, optional) – Maximum number of digits to print. May be None if unique is
True, but must be an integer if unique is False.
unique (boolean, optional) – If True, use a digit-generation strategy which gives the shortest
representation which uniquely identifies the floating-point number from
other values of the same type, by judicious rounding. If precision
is given fewer digits than necessary can be printed, or if min_digits
is given more can be printed, in which cases the last digit is rounded
with unbiased rounding.
If False, digits are generated as if printing an infinite-precision
value and stopping after precision digits, rounding the remaining
value with unbiased rounding
fractional (boolean, optional) – If True, the cutoffs of precision and min_digits refer to the
total number of digits after the decimal point, including leading
zeros.
If False, precision and min_digits refer to the total number of
significant digits, before or after the decimal point, ignoring leading
zeros.
trim (one of 'k', '.', '0', '-', optional) –
Controls post-processing trimming of trailing digits, as follows:
’k’ : keep trailing zeros, keep decimal point (no trimming)
’.’ : trim all trailing zeros, leave decimal point
’0’ : trim all but the zero before the decimal point. Insert the
zero if it is missing.
’-’ : trim trailing zeros and any trailing decimal point
sign (boolean, optional) – Whether to show the sign for positive values.
pad_left (non-negative integer, optional) – Pad the left side of the string with whitespace until at least that
many characters are to the left of the decimal point.
pad_right (non-negative integer, optional) – Pad the right side of the string with whitespace until at least that
many characters are to the right of the decimal point.
min_digits (non-negative integer or None, optional) –
Minimum number of digits to print. Only has an effect if unique=True
in which case additional digits past those necessary to uniquely
identify the value may be printed, rounding the last additional digit.
– versionadded:: 1.21.0
Returns:
rep – The string representation of the floating point value
Format a floating-point scalar as a decimal string in scientific notation.
Provides control over rounding, trimming and padding. Uses and assumes
IEEE unbiased rounding. Uses the “Dragon4” algorithm.
Parameters:
x (python float or numpy floating scalar) – Value to format.
precision (non-negative integer or None, optional) – Maximum number of digits to print. May be None if unique is
True, but must be an integer if unique is False.
unique (boolean, optional) – If True, use a digit-generation strategy which gives the shortest
representation which uniquely identifies the floating-point number from
other values of the same type, by judicious rounding. If precision
is given fewer digits than necessary can be printed. If min_digits
is given more can be printed, in which cases the last digit is rounded
with unbiased rounding.
If False, digits are generated as if printing an infinite-precision
value and stopping after precision digits, rounding the remaining
value with unbiased rounding
trim (one of 'k', '.', '0', '-', optional) –
Controls post-processing trimming of trailing digits, as follows:
’k’ : keep trailing zeros, keep decimal point (no trimming)
’.’ : trim all trailing zeros, leave decimal point
’0’ : trim all but the zero before the decimal point. Insert the
zero if it is missing.
’-’ : trim trailing zeros and any trailing decimal point
sign (boolean, optional) – Whether to show the sign for positive values.
pad_left (non-negative integer, optional) – Pad the left side of the string with whitespace until at least that
many characters are to the left of the decimal point.
exp_digits (non-negative integer, optional) – Pad the exponent with zeros until it contains at least this many digits.
If omitted, the exponent will be at least 2 digits.
min_digits (non-negative integer or None, optional) –
Minimum number of digits to print. This only has an effect for
unique=True. In that case more digits than necessary to uniquely
identify the value may be printed and rounded unbiased.
– versionadded:: 1.21.0
Returns:
rep – The string representation of the floating point value
formats (str or list of str) – The format description, either specified as a string with
comma-separated format descriptions in the form 'f8,i4,a5', or
a list of format description strings in the form
['f8','i4','a5'].
names (str or list/tuple of str) – The field names, either specified as a comma-separated string in the
form 'col1,col2,col3', or as a list or tuple of strings in the
form ['col1','col2','col3'].
An empty list can be used, in that case default field names
(‘f0’, ‘f1’, …) are used.
titles (sequence) – Sequence of title strings. An empty list can be used to leave titles
out.
aligned (bool, optional) – If True, align the fields by padding as the C-compiler would.
Default is False.
byteorder (str, optional) – If specified, all the fields will be changed to the
provided byte-order. Otherwise, the default byte-order is
used. For all available string specifiers, see dtype.newbyteorder.
names and/or titles can be empty lists. If titles is an empty list,
titles will simply not appear. If names is empty, default field names
will be used.
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.
Returns True if the type of element is a scalar type.
Parameters:
element (any) – Input argument, can be of any type and shape.
Returns:
val – True if element is a scalar type, False if it is not.
Return type:
bool
See also
ndim
Get the number of dimensions of an array
Notes
If you need a stricter way to identify a numerical scalar, use
isinstance(x,numbers.Number), as that returns False for most
non-numerical elements such as strings.
In most cases np.ndim(x)==0 should be used instead of this function,
as that will also return true for 0d arrays. This is how numpy overloads
functions in the style of the dx arguments to gradient and the bins
argument to histogram. Some key differences:
x
isscalar(x)
np.ndim(x)==0
PEP 3141 numeric objects (including
builtins)
True
True
builtin string and buffer objects
True
True
other builtin objects, like
pathlib.Path, Exception,
the result of re.compile
Determine if a class is a subclass of a second class.
issubclass_ is equivalent to the Python built-in issubclass,
except that it returns False instead of raising a TypeError if one
of the arguments is not a class.
Parameters:
arg1 (class) – Input class. True is returned if arg1 is a subclass of arg2.
arg2 (class or tuple of classes.) – Input class. If a tuple of classes, True is returned if arg1 is a
subclass of any of the tuple elements.
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.
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.
D.update([E, ]**F) -> None. Update D from dict/iterable E and F.
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k]
If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v
In either case, this is followed by: for k in F: D[k] = F[k]
D.update([E, ]**F) -> None. Update D from dict/iterable E and F.
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k]
If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v
In either case, this is followed by: for k in F: D[k] = F[k]
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.