diff options
| author | Ross Barnowski <rossbar@berkeley.edu> | 2022-01-28 12:46:11 -0800 |
|---|---|---|
| committer | Sebastian Berg <sebastian@sipsolutions.net> | 2022-01-28 15:06:49 -0600 |
| commit | 0ee03c847469a89a8b0e8a2584853151f6795d72 (patch) | |
| tree | fd0a3b7668b67ed26dcc3addd32dd2f87df3589a /numpy/lib | |
| parent | 8a31abccb1928d3ca1e669e105020f3a21dfb1a8 (diff) | |
| download | numpy-0ee03c847469a89a8b0e8a2584853151f6795d72.tar.gz | |
Add test for str dtype len discovery with converters.
nrows gt chunksize.
Diffstat (limited to 'numpy/lib')
| -rw-r--r-- | numpy/lib/tests/test_loadtxt.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/numpy/lib/tests/test_loadtxt.py b/numpy/lib/tests/test_loadtxt.py index b1e867157..3aa16eeb0 100644 --- a/numpy/lib/tests/test_loadtxt.py +++ b/numpy/lib/tests/test_loadtxt.py @@ -936,7 +936,7 @@ def test_control_character_newline_raises(nl): ], ) @pytest.mark.parametrize("nrows", (10, 50000, 60000)) # lt, eq, gt chunksize -def test_datetime_parametric_unit_discovery( +def test_parametric_unit_discovery( generic_data, long_datum, unitless_dtype, expected_dtype, nrows ): """Check that the correct unit (e.g. month, day, second) is discovered from @@ -960,6 +960,28 @@ def test_datetime_parametric_unit_discovery( assert_equal(a, expected) +def test_str_dtype_unit_discovery_with_converter(): + data = ["spam-a-lot"] * 60000 + ["XXXtis_but_a_scratch"] + expected = np.array( + ["spam-a-lot"] * 60000 + ["tis_but_a_scratch"], dtype="U17" + ) + conv = lambda s: s.strip("XXX") + + # file-like path + txt = StringIO("\n".join(data)) + a = np.loadtxt(txt, dtype="U", converters=conv, encoding=None) + assert a.dtype == expected.dtype + assert_equal(a, expected) + + # file-obj path + fd, fname = mkstemp() + with open(fname, "w") as fh: + fh.write("\n".join(data)) + a = np.loadtxt(fname, dtype="U", converters=conv, encoding=None) + assert a.dtype == expected.dtype + assert_equal(a, expected) + + def test_control_character_empty(): with pytest.raises(TypeError, match="Text reading control character must"): np.loadtxt(StringIO("1 2 3"), delimiter="") |
