summaryrefslogtreecommitdiff
path: root/numpy/lib/_datasource.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2018-08-10 13:23:23 -0600
committerCharles Harris <charlesr.harris@gmail.com>2018-08-10 16:06:41 -0600
commit007db13f45b378b3c7d6fe9c2d79d8ef1c700bbd (patch)
tree3b68fc838dc58db27720db4768d3e2510992fe0b /numpy/lib/_datasource.py
parentc0b4340c698c486e459a0a2c80706c78329c64fc (diff)
downloadnumpy-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/_datasource.py')
-rw-r--r--numpy/lib/_datasource.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/numpy/lib/_datasource.py b/numpy/lib/_datasource.py
index 6f1295f09..ab00b1444 100644
--- a/numpy/lib/_datasource.py
+++ b/numpy/lib/_datasource.py
@@ -37,6 +37,7 @@ from __future__ import division, absolute_import, print_function
import os
import sys
+import warnings
import shutil
import io
@@ -85,9 +86,10 @@ def _python2_bz2open(fn, mode, encoding, newline):
if "t" in mode:
# BZ2File is missing necessary functions for TextIOWrapper
- raise ValueError("bz2 text files not supported in python2")
- else:
- return bz2.BZ2File(fn, mode)
+ warnings.warn("Assuming latin1 encoding for bz2 text file in Python2",
+ RuntimeWarning, stacklevel=5)
+ mode = mode.replace("t", "")
+ return bz2.BZ2File(fn, mode)
def _python2_gzipopen(fn, mode, encoding, newline):
""" Wrapper to open gzip in text mode.