@@ -1877,3 +1877,91 @@ def test_large_int():
18771877 navdata ["numbers" ] = test_list
18781878
18791879 np .testing .assert_array_equal (navdata ["numbers" ], test_list )
1880+
1881+ def test_find_wildcard_indexes (data ):
1882+ """Tests find_wildcard_indexes
1883+
1884+ """
1885+
1886+ all_matching = data .rename ({"names" : "x_alpha_m" ,
1887+ "integers" : "x_beta_m" ,
1888+ "floats" : "x_gamma_m" ,
1889+ "strings" : "x_zeta_m" })
1890+ expected = ["x_alpha_m" ,"x_beta_m" ,"x_gamma_m" ,"x_zeta_m" ]
1891+
1892+ indexes = all_matching .find_wildcard_indexes ("x_*_m" )
1893+ assert indexes ["x_*_m" ] == expected
1894+ expect_pass_allows = [None ,12 ,4 ]
1895+ for max_allow in expect_pass_allows :
1896+ indexes = all_matching .find_wildcard_indexes ("x_*_m" ,max_allow )
1897+ assert indexes ["x_*_m" ] == expected
1898+
1899+ expect_fail_allows = [0 ,- 1 ,3 ,2 ,1 ]
1900+ for max_allow in expect_fail_allows :
1901+ with pytest .raises (KeyError ) as excinfo :
1902+ all_matching .find_wildcard_indexes ("x_*_m" ,max_allow )
1903+ assert "More than " + str (max_allow ) in str (excinfo .value )
1904+ assert "x_*_m" in str (excinfo .value )
1905+
1906+ multi = data .rename ({"names" : "x_alpha_m" ,
1907+ "integers" : "x_beta_m" ,
1908+ "floats" : "y_alpha_deg" ,
1909+ "strings" : "x_zeta_deg" })
1910+ expected = {"x_*_m" : ["x_alpha_m" ,"x_beta_m" ],
1911+ "y_*_deg" : ["y_alpha_deg" ]}
1912+
1913+ expect_pass_allows = [None ,2 ,4 ]
1914+ for max_allow in expect_pass_allows :
1915+ indexes = multi .find_wildcard_indexes (["x_*_m" ,"y_*_deg" ],
1916+ max_allow )
1917+ assert indexes == expected
1918+
1919+ expect_pass_allows = [None ,2 ,4 ]
1920+ for max_allow in expect_pass_allows :
1921+ indexes = multi .find_wildcard_indexes (tuple (["x_*_m" ,"y_*_deg" ]),
1922+ max_allow )
1923+ assert indexes == expected
1924+
1925+ expect_pass_allows = [None ,2 ,4 ]
1926+ for max_allow in expect_pass_allows :
1927+ indexes = multi .find_wildcard_indexes (set (["x_*_m" ,"y_*_deg" ]),
1928+ max_allow )
1929+ assert indexes == expected
1930+
1931+ expect_pass_allows = [None ,2 ,4 ]
1932+ for max_allow in expect_pass_allows :
1933+ indexes = multi .find_wildcard_indexes (np .array (["x_*_m" ,
1934+ "y_*_deg" ]),
1935+ max_allow )
1936+ assert indexes == expected
1937+
1938+ expect_fail_allows = [0 ,- 1 ,1 ]
1939+ for max_allow in expect_fail_allows :
1940+ with pytest .raises (KeyError ) as excinfo :
1941+ multi .find_wildcard_indexes (["x_*_m" ,"y_*_deg" ],max_allow )
1942+ assert "More than " + str (max_allow ) in str (excinfo .value )
1943+ assert "x_*_m" in str (excinfo .value )
1944+
1945+ with pytest .raises (KeyError ) as excinfo :
1946+ multi .find_wildcard_indexes (["z_*_m" ])
1947+ assert "Missing " in str (excinfo .value )
1948+ assert "z_*_m" in str (excinfo .value )
1949+
1950+ with pytest .raises (TypeError ) as excinfo :
1951+ multi .find_wildcard_indexes (1.0 )
1952+ assert "find_wildcard_indexes " in str (excinfo .value )
1953+ assert "array-like" in str (excinfo .value )
1954+
1955+ with pytest .raises (TypeError ) as excinfo :
1956+ multi .find_wildcard_indexes ([1.0 ])
1957+ assert "wildcards must be strings" in str (excinfo .value )
1958+
1959+ with pytest .raises (RuntimeError ) as excinfo :
1960+ multi .find_wildcard_indexes ("x_*_*" )
1961+ assert "One wildcard" in str (excinfo .value )
1962+
1963+ incorrect_max_allow = [3. ,"hi" ,[]]
1964+ for max_allow in incorrect_max_allow :
1965+ with pytest .raises (TypeError ) as excinfo :
1966+ multi .find_wildcard_indexes ("x_*_m" ,max_allow )
1967+ assert "max_allow" in str (excinfo .value )
0 commit comments