@@ -2313,24 +2313,7 @@ def test_datetime64_no_format():
23132313
23142314
23152315def test_hash_time ():
2316- loc1 = EarthLocation (1 * u .m , 2 * u .m , 3 * u .m )
2317- for loc in None , loc1 :
2318- t = Time ([1 , 1 , 2 , 3 ], format = "cxcsec" , location = loc )
2319- t [3 ] = np .ma .masked
2320- h1 = hash (t [0 ])
2321- h2 = hash (t [1 ])
2322- h3 = hash (t [2 ])
2323- assert h1 == h2
2324- assert h1 != h3
2325-
2326- with pytest .raises (TypeError ) as exc :
2327- hash (t )
2328- assert exc .value .args [0 ] == "unhashable type: 'Time' (must be scalar)"
2329-
2330- with pytest .raises (TypeError ) as exc :
2331- hash (t [3 ])
2332- assert exc .value .args [0 ] == "unhashable type: 'Time' (value is masked)"
2333-
2316+ loc = EarthLocation (1 * u .m , 2 * u .m , 3 * u .m )
23342317 t = Time (1 , format = "cxcsec" , location = loc )
23352318 t2 = Time (1 , format = "cxcsec" )
23362319
@@ -2342,22 +2325,53 @@ def test_hash_time():
23422325 assert hash (t ) != hash (t2 )
23432326
23442327
2345- def test_hash_time_delta ():
2328+ @pytest .mark .parametrize ("location" , [None , EarthLocation (1 * u .m , 2 * u .m , 3 * u .m )])
2329+ @pytest .mark .parametrize ("masked_array_type" , ["numpy" , "astropy" ])
2330+ def test_hash_masked_time (location , masked_array_type ):
2331+ t = Time ([1 , 1 , 2 , 3 ], format = "cxcsec" , location = location )
2332+ t [3 ] = np .ma .masked
2333+ with conf .set_temp ("masked_array_type" , masked_array_type ):
2334+ if masked_array_type == "numpy" :
2335+ h1 = hash (t [0 ])
2336+ h2 = hash (t [1 ])
2337+ h3 = hash (t [2 ])
2338+ assert h1 == h2
2339+ assert h1 != h3
2340+ else :
2341+ with pytest .raises (TypeError , match = "value is masked" ):
2342+ hash (t [0 ])
2343+
2344+ with pytest .raises (
2345+ TypeError , match = r"unhashable type: 'Time' \(must be scalar\)"
2346+ ):
2347+ hash (t )
2348+
2349+ with pytest .raises (
2350+ TypeError , match = r"unhashable type: 'Time' \(value is masked\)"
2351+ ):
2352+ hash (t [3 ])
2353+
2354+
2355+ @pytest .mark .parametrize ("masked_array_type" , ["numpy" , "astropy" ])
2356+ def test_hash_time_delta_masked (masked_array_type ):
23462357 t = TimeDelta ([1 , 1 , 2 , 3 ], format = "sec" )
23472358 t [3 ] = np .ma .masked
2348- h1 = hash (t [0 ])
2349- h2 = hash (t [1 ])
2350- h3 = hash (t [2 ])
2351- assert h1 == h2
2352- assert h1 != h3
2353-
2354- with pytest .raises (TypeError ) as exc :
2355- hash (t )
2356- assert exc .value .args [0 ] == "unhashable type: 'TimeDelta' (must be scalar)"
2357-
2358- with pytest .raises (TypeError ) as exc :
2359- hash (t [3 ])
2360- assert exc .value .args [0 ] == "unhashable type: 'TimeDelta' (value is masked)"
2359+ with conf .set_temp ("masked_array_type" , masked_array_type ):
2360+ if masked_array_type == "numpy" :
2361+ h1 = hash (t [0 ])
2362+ h2 = hash (t [1 ])
2363+ h3 = hash (t [2 ])
2364+ assert h1 == h2
2365+ assert h1 != h3
2366+ else :
2367+ with pytest .raises (TypeError , match = r"'TimeDelta' \(value is masked\)" ):
2368+ hash (t [0 ])
2369+
2370+ with pytest .raises (TypeError , match = r"'TimeDelta' \(must be scalar\)" ):
2371+ hash (t )
2372+
2373+ with pytest .raises (TypeError , match = r"'TimeDelta' \(value is masked\)" ):
2374+ hash (t [3 ])
23612375
23622376
23632377def test_get_time_fmt_exception_messages ():
0 commit comments