@@ -758,6 +758,47 @@ def test_lazyexpr_fields(auth_client):
758
758
[np .testing .assert_array_equal (servered [f ], downloaded [f ]) for f in downloaded .dtype .fields ]
759
759
760
760
761
+ def test_lazyexpr_cache (auth_client ):
762
+ if not auth_client :
763
+ pytest .skip ("authentication support needed" )
764
+
765
+ root = auth_client .get ("@personal" )
766
+ oppt = f"{ root .name } /sa-1M.b2nd"
767
+
768
+ N = 1000
769
+ rng = np .random .default_rng (seed = 1 )
770
+ it = ((- x + 1 , x - 2 , x ) for x in range (N ))
771
+ sa = blosc2 .fromiter (
772
+ it , dtype = [("A" , "i4" ), ("B" , "f4" ), ("C" , "f8" )], shape = (N ,), urlpath = "sa-1M.b2nd" , mode = "w"
773
+ )
774
+ path = auth_client .upload ("sa-1M.b2nd" , oppt )
775
+ arr = auth_client .get (path )
776
+
777
+ # Test a lazyexpr
778
+ arr = auth_client .get (oppt )
779
+ servered = arr ["(A < 500) & (B >= .1)" ][:]
780
+ downloaded = arr .slice (None )["(A < 500) & (B >= .1)" ][:]
781
+ [np .testing .assert_array_equal (servered [f ], downloaded [f ]) for f in downloaded .dtype .fields ]
782
+
783
+ # Overwrite the file and check that cache isn't used
784
+ N = 10000
785
+ rng = np .random .default_rng (seed = 1 )
786
+ it = ((- x + 1 , x - 2 , x ) for x in range (N ))
787
+ sa = blosc2 .fromiter (
788
+ it , dtype = [("A" , "i4" ), ("B" , "f4" ), ("C" , "f8" )], shape = (N ,), urlpath = "sa-1M.b2nd" , mode = "w"
789
+ )
790
+ path = auth_client .upload ("sa-1M.b2nd" , oppt )
791
+ arr = auth_client .get (path )
792
+
793
+ # Test lazyexpr again
794
+ servered = arr ["(A < - 500) & (B >= .1)" ][:]
795
+ downloaded = arr .slice (None )["(A < - 500) & (B >= .1)" ][:]
796
+ [np .testing .assert_allclose (servered [f ], downloaded [f ]) for f in downloaded .dtype .fields ]
797
+
798
+ # remove file
799
+ arr .remove ()
800
+
801
+
761
802
def test_expr_from_expr (auth_client ):
762
803
if not auth_client :
763
804
pytest .skip ("authentication support needed" )
0 commit comments