diff options
| author | Alexander Heger <2sn@users.noreply.github.com> | 2023-02-12 00:26:42 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-11 14:26:42 +0100 |
| commit | 8daec0ecf11f9d2633d133f2d2b7d6c39f157f4b (patch) | |
| tree | 82cbd956320149c1b68348b9eb9767ac48923d36 /numpy/f2py/tests | |
| parent | 6dadb8c40451e934075904f6acdfe341d3b8762e (diff) | |
| download | numpy-8daec0ecf11f9d2633d133f2d2b7d6c39f157f4b.tar.gz | |
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
Diffstat (limited to 'numpy/f2py/tests')
| -rw-r--r-- | numpy/f2py/tests/src/string/scalar_string.f90 | 7 | ||||
| -rw-r--r-- | numpy/f2py/tests/test_character.py | 20 |
2 files changed, 27 insertions, 0 deletions
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 |
