diff options
author | Ross Barnowski <rossbar@berkeley.edu> | 2022-01-11 10:45:28 -0800 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2022-01-14 20:07:07 -0600 |
commit | 530c954316680f234b6926d0188843bca56de90d (patch) | |
tree | 73fea05451529258701f0ba3baadf2bf51220977 /numpy/lib/tests | |
parent | 10b04d65bfb403d38f6d5c0de40e26ba1849d10d (diff) | |
download | numpy-530c954316680f234b6926d0188843bca56de90d.tar.gz |
Add UserWarning when reading no data.
Diffstat (limited to 'numpy/lib/tests')
-rw-r--r-- | numpy/lib/tests/test_io.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index 7cc1b7ede..4a5cc1ad8 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -3242,3 +3242,26 @@ def test_loadtxt_consecutive_quotechar_escaped(): expected = np.array('Hello, my name is "Monty"!', dtype="U40") res = np.loadtxt(txt, dtype="U40", delimiter=",", quotechar='"') assert_equal(res, expected) + + +@pytest.mark.parametrize("data", ("", "\n\n\n", "# 1 2 3\n# 4 5 6\n")) +@pytest.mark.parametrize("ndmin", (0, 1, 2)) +def test_loadtxt_warn_on_no_data(data, ndmin): + """Check that a UserWarning is emitted when no data is read from input.""" + txt = TextIO(data) + with pytest.warns(UserWarning, match="input contained no data"): + np.loadtxt(txt, ndmin=ndmin) + + with NamedTemporaryFile(mode="w") as fh: + fh.write(data) + fh.seek(0) + with pytest.warns(UserWarning, match="input contained no data"): + np.loadtxt(txt, ndmin=ndmin) + + +@pytest.mark.parametrize("skiprows", (2, 3)) +def test_loadtxt_warn_on_skipped_data(skiprows): + data = "1 2 3\n4 5 6" + txt = TextIO(data) + with pytest.warns(UserWarning, match="input contained no data"): + np.loadtxt(txt, skiprows=skiprows) |