Skip to content

Commit

Permalink
* _iotools.LineSplitter : prevent the first and/or last empty tab-sep…
Browse files Browse the repository at this point in the history
…arated columns to be dropped
  • Loading branch information
pierregm committed Dec 8, 2009
1 parent 846d905 commit 06a0a53
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 54 deletions.
16 changes: 8 additions & 8 deletions numpy/lib/_iotools.py
Expand Up @@ -166,8 +166,8 @@ def __init__(self, delimiter=None, comments='#', autostrip=True):
# Delimiter is a list of field widths
elif hasattr(delimiter, '__iter__'):
_handyman = self._variablewidth_splitter
idx = np.cumsum([0]+list(delimiter))
delimiter = [slice(i,j) for (i,j) in zip(idx[:-1], idx[1:])]
idx = np.cumsum([0] + list(delimiter))
delimiter = [slice(i, j) for (i, j) in zip(idx[:-1], idx[1:])]
# Delimiter is a single integer
elif int(delimiter):
(_handyman, delimiter) = (self._fixedwidth_splitter, int(delimiter))
Expand All @@ -180,7 +180,7 @@ def __init__(self, delimiter=None, comments='#', autostrip=True):
self._handyman = _handyman
#
def _delimited_splitter(self, line):
line = line.split(self.comments)[0].strip()
line = line.split(self.comments)[0].strip(" \r\n")
if not line:
return []
return line.split(self.delimiter)
Expand All @@ -190,7 +190,7 @@ def _fixedwidth_splitter(self, line):
if not line:
return []
fixed = self.delimiter
slices = [slice(i, i+fixed) for i in range(len(line))[::fixed]]
slices = [slice(i, i + fixed) for i in range(len(line))[::fixed]]
return [line[s] for s in slices]
#
def _variablewidth_splitter(self, line):
Expand Down Expand Up @@ -255,7 +255,7 @@ class NameValidator:
"""
#
defaultexcludelist = ['return','file','print']
defaultexcludelist = ['return', 'file', 'print']
defaultdeletechars = set("""~!@#$%^&*()-=+~\|]}[{';: /?.>,<""")
#
def __init__(self, excludelist=None, deletechars=None, case_sensitive=None):
Expand Down Expand Up @@ -313,7 +313,7 @@ def validate(self, names, defaultfmt="f%i", nbfields=None):
return None
names = []
if isinstance(names, basestring):
names = [names,]
names = [names, ]
if nbfields is not None:
nbnames = len(names)
if (nbnames < nbfields):
Expand Down Expand Up @@ -468,7 +468,7 @@ class StringConverter:
_mapper = [(nx.bool_, str2bool, False),
(nx.integer, int, -1),
(nx.floating, float, nx.nan),
(complex, complex, nx.nan+0j),
(complex, complex, nx.nan + 0j),
(nx.string_, str, '???')]
(_defaulttype, _defaultfunc, _defaultfill) = zip(*_mapper)
#
Expand Down Expand Up @@ -513,7 +513,7 @@ def upgrade_mapper(cls, func, default=None):
default = [None] * len(func)
else:
default = list(default)
default.append([None] * (len(func)-len(default)))
default.append([None] * (len(func) - len(default)))
for (fct, dft) in zip(func, default):
cls._mapper.insert(-1, (cls._getsubdtype(dft), fct, dft))
#
Expand Down

0 comments on commit 06a0a53

Please sign in to comment.