diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2018-08-10 13:23:23 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2018-08-10 16:06:41 -0600 |
commit | 007db13f45b378b3c7d6fe9c2d79d8ef1c700bbd (patch) | |
tree | 3b68fc838dc58db27720db4768d3e2510992fe0b /numpy/lib/tests/test__datasource.py | |
parent | c0b4340c698c486e459a0a2c80706c78329c64fc (diff) | |
download | numpy-007db13f45b378b3c7d6fe9c2d79d8ef1c700bbd.tar.gz |
BUG: Fix regression in loadtxt for bz2 text files in Python 2.
Text bz2 files are not well supported in Python2, and, following the
NumPy upgrade in text handling, loadtxt was raising an error when they
were detected. This led to problems for those few who were using such
files. This patch is a quick fix that issues a RuntimeWarning, then
opens those files under the assumption that they are latin1 encoded.
Caveat emptor.
Closes #11633.
Diffstat (limited to 'numpy/lib/tests/test__datasource.py')
-rw-r--r-- | numpy/lib/tests/test__datasource.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/numpy/lib/tests/test__datasource.py b/numpy/lib/tests/test__datasource.py index 32812990c..70fff3bb0 100644 --- a/numpy/lib/tests/test__datasource.py +++ b/numpy/lib/tests/test__datasource.py @@ -2,11 +2,14 @@ from __future__ import division, absolute_import, print_function import os import sys +import pytest from tempfile import mkdtemp, mkstemp, NamedTemporaryFile from shutil import rmtree -from numpy.testing import assert_, assert_equal, assert_raises, SkipTest import numpy.lib._datasource as datasource +from numpy.testing import ( + assert_, assert_equal, assert_raises, assert_warns, SkipTest + ) if sys.version_info[0] >= 3: import urllib.request as urllib_request @@ -161,6 +164,24 @@ class TestDataSourceOpen(object): fp.close() assert_equal(magic_line, result) + @pytest.mark.skipif(sys.version_info[0] >= 3, reason="Python 2 only") + def test_Bz2File_text_mode_warning(self): + try: + import bz2 + except ImportError: + # We don't have the bz2 capabilities to test. + raise SkipTest + # Test datasource's internal file_opener for BZip2 files. + filepath = os.path.join(self.tmpdir, 'foobar.txt.bz2') + fp = bz2.BZ2File(filepath, 'w') + fp.write(magic_line) + fp.close() + with assert_warns(RuntimeWarning): + fp = self.ds.open(filepath, 'rt') + result = fp.readline() + fp.close() + assert_equal(magic_line, result) + class TestDataSourceExists(object): def setup(self): |