From 8daec0ecf11f9d2633d133f2d2b7d6c39f157f4b Mon Sep 17 00:00:00 2001 From: Alexander Heger <2sn@users.noreply.github.com> Date: Sun, 12 Feb 2023 00:26:42 +1100 Subject: BUG: fix for f2py string scalars (#23194) in previous version, any string scalar was converted to a string array of dimension len, i.e., a definition character(len=N) :: X effectively became character(len=NNN), dimension(NNN) :: X from the point of few of the numpy (python) interface: X.shape == (NNN,) X.dtype == '|SNNN' Closes gh-23192 --- numpy/f2py/tests/src/string/scalar_string.f90 | 7 +++++++ numpy/f2py/tests/test_character.py | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 numpy/f2py/tests/src/string/scalar_string.f90 (limited to 'numpy/f2py/tests') diff --git a/numpy/f2py/tests/src/string/scalar_string.f90 b/numpy/f2py/tests/src/string/scalar_string.f90 new file mode 100644 index 000000000..d847668bb --- /dev/null +++ b/numpy/f2py/tests/src/string/scalar_string.f90 @@ -0,0 +1,7 @@ +MODULE string_test + + character(len=8) :: string + + character(len=12), dimension(5,7) :: strarr + +END MODULE string_test diff --git a/numpy/f2py/tests/test_character.py b/numpy/f2py/tests/test_character.py index 528e78fc6..5f9805158 100644 --- a/numpy/f2py/tests/test_character.py +++ b/numpy/f2py/tests/test_character.py @@ -569,3 +569,23 @@ class TestMiscCharacter(util.F2PyTest): assert_equal(len(a), 2) assert_raises(Exception, lambda: f(b'c')) + + +class TestStringScalarArr(util.F2PyTest): + sources = [util.getpath("tests", "src", "string", "scalar_string.f90")] + + @pytest.mark.slow + def test_char(self): + out = self.module.string_test.string + expected = () + assert out.shape == expected + expected = '|S8' + assert out.dtype == expected + + @pytest.mark.slow + def test_char_arr(self): + out = self.module.string_test.strarr + expected = (5,7) + assert out.shape == expected + expected = '|S12' + assert out.dtype == expected -- cgit v1.2.1