Skip to content

Commit 7ca502e

Browse files
MAINT: io.open → open
In Python 3, io.open() is an alias for the builtin open() function: https://docs.python.org/3/library/io.html#io.open
1 parent 7669b86 commit 7ca502e

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

numpy/core/tests/test_multiarray.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -5361,15 +5361,15 @@ def test_unseekable_fromfile(self, x, tmp_filename):
53615361
def fail(*args, **kwargs):
53625362
raise OSError('Can not tell or seek')
53635363

5364-
with io.open(tmp_filename, 'rb', buffering=0) as f:
5364+
with open(tmp_filename, 'rb', buffering=0) as f:
53655365
f.seek = fail
53665366
f.tell = fail
53675367
assert_raises(OSError, np.fromfile, f, dtype=x.dtype)
53685368

53695369
def test_io_open_unbuffered_fromfile(self, x, tmp_filename):
53705370
# gh-6632
53715371
x.tofile(tmp_filename)
5372-
with io.open(tmp_filename, 'rb', buffering=0) as f:
5372+
with open(tmp_filename, 'rb', buffering=0) as f:
53735373
y = np.fromfile(f, dtype=x.dtype)
53745374
assert_array_equal(y, x.flat)
53755375

@@ -5396,7 +5396,7 @@ def test_largish_file(self, tmp_filename):
53965396
def test_io_open_buffered_fromfile(self, x, tmp_filename):
53975397
# gh-6632
53985398
x.tofile(tmp_filename)
5399-
with io.open(tmp_filename, 'rb', buffering=-1) as f:
5399+
with open(tmp_filename, 'rb', buffering=-1) as f:
54005400
y = np.fromfile(f, dtype=x.dtype)
54015401
assert_array_equal(y, x.flat)
54025402

numpy/lib/_datasource.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
3636
"""
3737
import os
38-
import io
3938

4039
from .._utils import set_module
4140

@@ -98,7 +97,7 @@ class _FileOpeners:
9897

9998
def __init__(self):
10099
self._loaded = False
101-
self._file_openers = {None: io.open}
100+
self._file_openers = {None: open}
102101

103102
def _load(self):
104103
if self._loaded:
@@ -173,7 +172,7 @@ def open(path, mode='r', destpath=os.curdir, encoding=None, newline=None):
173172
The default path is the current directory.
174173
encoding : {None, str}, optional
175174
Open text file with given encoding. The default encoding will be
176-
what `io.open` uses.
175+
what `open` uses.
177176
newline : {None, str}, optional
178177
Newline to use when reading text file.
179178
@@ -501,7 +500,7 @@ def open(self, path, mode='r', encoding=None, newline=None):
501500
specified by `path`. Default is 'r'.
502501
encoding : {None, str}, optional
503502
Open text file with given encoding. The default encoding will be
504-
what `io.open` uses.
503+
what `open` uses.
505504
newline : {None, str}, optional
506505
Newline to use when reading text file.
507506
@@ -670,7 +669,7 @@ def open(self, path, mode='r', encoding=None, newline=None):
670669
specified by `path`. Default is 'r'.
671670
encoding : {None, str}, optional
672671
Open text file with given encoding. The default encoding will be
673-
what `io.open` uses.
672+
what `open` uses.
674673
newline : {None, str}, optional
675674
Newline to use when reading text file.
676675

numpy/lib/tests/test_io.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import threading
66
import time
77
import warnings
8-
import io
98
import re
109
import pytest
1110
from pathlib import Path
@@ -701,7 +700,7 @@ def test_converters_nodecode(self):
701700
# test native string converters enabled by setting an encoding
702701
utf8 = b'\xcf\x96'.decode('UTF-8')
703702
with temppath() as path:
704-
with io.open(path, 'wt', encoding='UTF-8') as f:
703+
with open(path, 'wt', encoding='UTF-8') as f:
705704
f.write(utf8)
706705
x = self.loadfunc(path, dtype=np.str_,
707706
converters={0: lambda x: x + 't'},
@@ -2264,7 +2263,7 @@ def test_utf8_file_nodtype_unicode(self):
22642263

22652264
# skip test if cannot encode utf8 test string with preferred
22662265
# encoding. The preferred encoding is assumed to be the default
2267-
# encoding of io.open. Will need to change this for PyTest, maybe
2266+
# encoding of open. Will need to change this for PyTest, maybe
22682267
# using pytest.mark.xfail(raises=***).
22692268
try:
22702269
encoding = locale.getpreferredencoding()
@@ -2274,7 +2273,7 @@ def test_utf8_file_nodtype_unicode(self):
22742273
'unable to encode utf8 in preferred encoding')
22752274

22762275
with temppath() as path:
2277-
with io.open(path, "wt") as f:
2276+
with open(path, "wt") as f:
22782277
f.write("norm1,norm2,norm3\n")
22792278
f.write("norm1," + latin1 + ",norm3\n")
22802279
f.write("test1,testNonethe" + utf8 + ",test3\n")

0 commit comments

Comments
 (0)