summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorDima Pasechnik <dimpase@gmail.com>2021-09-28 18:14:14 +0100
committerGitHub <noreply@github.com>2021-09-28 18:14:14 +0100
commit0131b0aa13bcc027d8733120a6304db52fd8a2b2 (patch)
tree666df30bb89b7e0f48f5eed56fb857632b183113 /numpy
parent1ac3cbea412c7d9ff467a8e599609621887c6cdd (diff)
parent7d2904b45abb0a56e70b1710b140ba7cc50cd766 (diff)
downloadnumpy-0131b0aa13bcc027d8733120a6304db52fd8a2b2.tar.gz
Merge branch 'numpy:main' into master
Diffstat (limited to 'numpy')
-rw-r--r--numpy/ma/mrecords.py14
-rw-r--r--numpy/ma/mrecords.pyi2
-rw-r--r--numpy/ma/tests/test_deprecations.py21
3 files changed, 36 insertions, 1 deletions
diff --git a/numpy/ma/mrecords.py b/numpy/ma/mrecords.py
index bdce8b3bd..2ce1f0a23 100644
--- a/numpy/ma/mrecords.py
+++ b/numpy/ma/mrecords.py
@@ -668,7 +668,8 @@ def openfile(fname):
def fromtextfile(fname, delimiter=None, commentchar='#', missingchar='',
- varnames=None, vartypes=None):
+ varnames=None, vartypes=None,
+ *, delimitor=np._NoValue): # backwards compatibility
"""
Creates a mrecarray from data stored in the file `filename`.
@@ -692,6 +693,17 @@ def fromtextfile(fname, delimiter=None, commentchar='#', missingchar='',
Ultra simple: the varnames are in the header, one line"""
+ if delimitor is not np._NoValue:
+ if delimiter is not None:
+ raise TypeError("fromtextfile() got multiple values for argument "
+ "'delimiter'")
+ # NumPy 1.22.0, 2021-09-23
+ warnings.warn("The 'delimitor' keyword argument of "
+ "numpy.ma.mrecords.fromtextfile() is deprecated "
+ "since NumPy 1.22.0, use 'delimiter' instead.",
+ DeprecationWarning, stacklevel=2)
+ delimiter = delimitor
+
# Try to open the file.
ftext = openfile(fname)
diff --git a/numpy/ma/mrecords.pyi b/numpy/ma/mrecords.pyi
index cdd5347d6..7bd8678cf 100644
--- a/numpy/ma/mrecords.pyi
+++ b/numpy/ma/mrecords.pyi
@@ -83,6 +83,8 @@ def fromtextfile(
missingchar=...,
varnames=...,
vartypes=...,
+ # NOTE: deprecated: NumPy 1.22.0, 2021-09-23
+ # delimitor=...,
): ...
def addfield(mrecord, newfield, newfieldname=...): ...
diff --git a/numpy/ma/tests/test_deprecations.py b/numpy/ma/tests/test_deprecations.py
index 14f697375..3e0e09fdd 100644
--- a/numpy/ma/tests/test_deprecations.py
+++ b/numpy/ma/tests/test_deprecations.py
@@ -1,10 +1,13 @@
"""Test deprecation and future warnings.
"""
+import pytest
import numpy as np
from numpy.testing import assert_warns
from numpy.ma.testutils import assert_equal
from numpy.ma.core import MaskedArrayFutureWarning
+import io
+import textwrap
class TestArgsort:
""" gh-8701 """
@@ -66,3 +69,21 @@ class TestMinimumMaximum:
result = ma_max(data1d)
assert_equal(result, ma_max(data1d, axis=None))
assert_equal(result, ma_max(data1d, axis=0))
+
+
+class TestFromtextfile:
+ def test_fromtextfile_delimitor(self):
+ # NumPy 1.22.0, 2021-09-23
+
+ textfile = io.StringIO(textwrap.dedent(
+ """
+ A,B,C,D
+ 'string 1';1;1.0;'mixed column'
+ 'string 2';2;2.0;
+ 'string 3';3;3.0;123
+ 'string 4';4;4.0;3.14
+ """
+ ))
+
+ with pytest.warns(DeprecationWarning):
+ result = np.ma.mrecords.fromtextfile(textfile, delimitor=';')