summaryrefslogtreecommitdiff
path: root/numpy/lib/npyio.py
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2021-12-08 12:54:40 -0600
committerSebastian Berg <sebastian@sipsolutions.net>2022-01-14 20:07:07 -0600
commit684cefc55eb781e91df9cbcb0e883d3ad09b0347 (patch)
tree17534b76c046f85b74e58c3ba92d0cb838e25290 /numpy/lib/npyio.py
parentff91f2b526abfa0dda31b32daf9468a65929acde (diff)
downloadnumpy-684cefc55eb781e91df9cbcb0e883d3ad09b0347.tar.gz
ENH: Allow a single converter to be used for all columns
This is always used if it is a callable.
Diffstat (limited to 'numpy/lib/npyio.py')
-rw-r--r--numpy/lib/npyio.py26
1 files changed, 14 insertions, 12 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
index c2472f601..f08f0c8f5 100644
--- a/numpy/lib/npyio.py
+++ b/numpy/lib/npyio.py
@@ -831,12 +831,13 @@ def _read(fname, *, delimiter=',', comment='#', quote='"',
max_rows : int, optional
Maximum number of rows of data to read. Default is to read the
entire file.
- converters : dict, optional
- A dictionary mapping column number to a function that will parse the
- column string into the desired value. E.g. if column 0 is a date
- string: ``converters = {0: datestr2num}``. Converters can also be used
- to provide a default value for missing data, e.g.
- ``converters = {3: lambda s: float(s.strip() or 0)}``.
+ converters : dict or callable, optional
+ A function to parse all columns strings into the desired value, or
+ a dictionary mapping column number to a parser function.
+ E.g. if column 0 is a date string: ``converters = {0: datestr2num}``.
+ Converters can also be used to provide a default value for missing
+ data, e.g. ``converters = lambda s: float(s.strip() or 0)`` will
+ convert empty fields to 0.
Default: None
ndmin : int, optional
Minimum dimension of the array returned.
@@ -1100,12 +1101,13 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None,
delimiter : str, optional
The string used to separate values. For backwards compatibility, byte
strings will be decoded as 'latin1'. The default is whitespace.
- converters : dict, optional
- A dictionary mapping column number to a function that will parse the
- column string into the desired value. E.g., if column 0 is a date
- string: ``converters = {0: datestr2num}``. Converters can also be
- used to provide a default value for missing data (but see also
- `genfromtxt`): ``converters = {3: lambda s: float(s.strip() or 0)}``.
+ converters : dict or callable, optional
+ A function to parse all columns strings into the desired value, or
+ a dictionary mapping column number to a parser function.
+ E.g. if column 0 is a date string: ``converters = {0: datestr2num}``.
+ Converters can also be used to provide a default value for missing
+ data, e.g. ``converters = lambda s: float(s.strip() or 0)`` will
+ convert empty fields to 0.
Default: None.
skiprows : int, optional
Skip the first `skiprows` lines, including comments; default: 0.