@@ -692,6 +692,51 @@ def test_decode_with_reshape(self):
692
692
assert_ (res .shape == (1 , 0 , 1 ))
693
693
694
694
695
+ class TestMethodsScalarValues :
696
+ def test_mod (self ):
697
+ A = np .array ([[' abc ' , '' ],
698
+ ['12345' , 'MixedCase' ],
699
+ ['123 \t 345 \0 ' , 'UPPER' ]], dtype = 'S' )
700
+ tgt = [[b'123 abc ' , b'123' ],
701
+ [b'12312345' , b'123MixedCase' ],
702
+ [b'123123 \t 345 \0 ' , b'123UPPER' ]]
703
+ assert_array_equal (np .char .mod (b"123%s" , A ), tgt )
704
+
705
+ def test_decode (self ):
706
+ bytestring = b'\x81 \xc1 \x81 \xc1 \x81 \xc1 '
707
+ assert_equal (np .char .decode (bytestring , encoding = 'cp037' ),
708
+ 'aAaAaA' )
709
+
710
+ def test_encode (self ):
711
+ unicode = 'aAaAaA'
712
+ assert_equal (np .char .encode (unicode , encoding = 'cp037' ),
713
+ b'\x81 \xc1 \x81 \xc1 \x81 \xc1 ' )
714
+
715
+ def test_expandtabs (self ):
716
+ s = "\t one level of indentation\n \t \t two levels of indentation"
717
+ assert_equal (
718
+ np .char .expandtabs (s , tabsize = 2 ),
719
+ " one level of indentation\n two levels of indentation"
720
+ )
721
+
722
+ def test_join (self ):
723
+ seps = np .array (['-' , '_' ])
724
+ assert_array_equal (np .char .join (seps , 'hello' ),
725
+ ['h-e-l-l-o' , 'h_e_l_l_o' ])
726
+
727
+ def test_partition (self ):
728
+ assert_equal (np .char .partition ('This string' , ' ' ),
729
+ ['This' , ' ' , 'string' ])
730
+
731
+ def test_rpartition (self ):
732
+ assert_equal (np .char .rpartition ('This string here' , ' ' ),
733
+ ['This string' , ' ' , 'here' ])
734
+
735
+ def test_replace (self ):
736
+ assert_equal (np .char .replace ('Python is good' , 'good' , 'great' ),
737
+ 'Python is great' )
738
+
739
+
695
740
def test_empty_indexing ():
696
741
"""Regression test for ticket 1948."""
697
742
# Check that indexing a chararray with an empty list/array returns an
0 commit comments