summaryrefslogtreecommitdiff
path: root/numpy/lib/npyio.py
diff options
context:
space:
mode:
authorRoss Barnowski <rossbar@berkeley.edu>2022-01-28 09:17:25 -0800
committerGitHub <noreply@github.com>2022-01-28 11:17:25 -0600
commitb335431699f86ab523dc6dba2c91efc799f4372b (patch)
tree17b544cf5a609746bd3b98c24f6db204efb9a39a /numpy/lib/npyio.py
parent763a3d4878671d383ba8aa573af90fee125efff4 (diff)
downloadnumpy-b335431699f86ab523dc6dba2c91efc799f4372b.tar.gz
TST: Some tests for control character collisions.
Adds some tests for the behavior of control characters, e.g. comments, delimiter and quotechar, when they have the same value. At this stage, these tests are more to frame the discussion about what the behavior should be, not to test what it currently is. I personally think raising an exception is correct for most of these situations, though it's worth noting that np.loadtxt currently doesn't for most of these corner cases (and seems to randomly assign precedence to delimiter over comments or vice versa depending on the values).
Diffstat (limited to 'numpy/lib/npyio.py')
-rw-r--r--numpy/lib/npyio.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
index 62d00cfb9..be313d104 100644
--- a/numpy/lib/npyio.py
+++ b/numpy/lib/npyio.py
@@ -920,12 +920,6 @@ def _read(fname, *, delimiter=',', comment='#', quote='"',
if comment is None:
comments = None
- elif isinstance(comment, str):
- if len(comment) > 1: # length of 0 is rejected later
- comments = (comment,)
- comment = None
- else:
- comments = None
else:
# assume comments are a sequence of strings
comments = tuple(comment)
@@ -938,6 +932,13 @@ def _read(fname, *, delimiter=',', comment='#', quote='"',
if isinstance(comments[0], str) and len(comments[0]) == 1:
comment = comments[0]
comments = None
+ else:
+ # Input validation if there are multiple comment characters
+ if delimiter in comments:
+ raise TypeError(
+ f"Comment characters '{comments}' cannot include the "
+ f"delimiter '{delimiter}'"
+ )
# comment is now either a 1 or 0 character string or a tuple:
if comments is not None: