@@ -820,20 +820,22 @@ def test_multi_index_timing(self):
820
820
assert "py.getitem_time.pandas_index_update_time :" in internal_stats
821
821
tiledb .stats_disable ()
822
822
823
- # parametrize dtype and sparse
824
- @pytest .mark .parametrize (
825
- "dim_dtype" ,
826
- [
827
- np .int64 ,
828
- np .uint64 ,
829
- np .int32 ,
830
- np .uint32 ,
831
- np .int16 ,
832
- np .uint16 ,
833
- np .int8 ,
834
- np .uint8 ,
835
- ],
836
- )
823
+
824
+ # parametrize dtype and sparse
825
+ @pytest .mark .parametrize (
826
+ "dim_dtype" ,
827
+ [
828
+ np .int64 ,
829
+ np .uint64 ,
830
+ np .int32 ,
831
+ np .uint32 ,
832
+ np .int16 ,
833
+ np .uint16 ,
834
+ np .int8 ,
835
+ np .uint8 ,
836
+ ],
837
+ )
838
+ class TestMultiIndexND (DiskTestCase ):
837
839
def test_multi_index_ndarray (self , dim_dtype ):
838
840
# TODO support for dense?
839
841
sparse = True # ndarray indexing currently only supported for sparse
@@ -865,3 +867,65 @@ def test_multi_index_ndarray(self, dim_dtype):
865
867
assert_dict_arrays_equal (
866
868
A .multi_index [coords .tolist ()], A .multi_index [coords ]
867
869
)
870
+ assert_dict_arrays_equal (
871
+ A .multi_index [coords .tolist ()], A .multi_index [coords ]
872
+ )
873
+
874
+ def test_multi_index_ndarray_2d (self , dim_dtype ):
875
+ sparse = False
876
+
877
+ path = self .path (f"test_multi_index_ndarray_2d" )
878
+
879
+ ncells = 10
880
+ ext = ncells - 1
881
+ if sparse :
882
+ data = np .arange (ext )
883
+ else :
884
+ data = np .arange (ext ** 2 ).reshape (ext , ext )
885
+ d1_coords = np .arange (ext )
886
+ d2_coords = np .arange (ext , 0 , - 1 )
887
+
888
+ # use negative range for sparse
889
+ if sparse and np .issubdtype (dim_dtype , np .signedinteger ):
890
+ d1_coords -= 4
891
+
892
+ d1 = tiledb .Dim (
893
+ name = "d1" , domain = (d1_coords .min (), d1_coords .max ()), dtype = dim_dtype
894
+ )
895
+ d2 = tiledb .Dim (
896
+ name = "d2" , domain = (d2_coords .min (), d2_coords .max ()), dtype = dim_dtype
897
+ )
898
+ dom = tiledb .Domain ([d1 , d2 ])
899
+
900
+ att = tiledb .Attr (dtype = np .int8 )
901
+ schema = tiledb .ArraySchema (domain = dom , attrs = (att ,), sparse = sparse )
902
+ tiledb .Array .create (path , schema )
903
+
904
+ with tiledb .open (path , "w" ) as A :
905
+ if sparse :
906
+ A [d1_coords .tolist (), d2_coords .tolist ()] = {"" : data }
907
+ else :
908
+ A [:] = data
909
+ # raise ValueError("Test only support sparse")
910
+
911
+ with tiledb .open (path ) as A :
912
+ assert_dict_arrays_equal (
913
+ A .multi_index [d1_coords .tolist (), d2_coords .tolist ()],
914
+ A .multi_index [d1_coords , d2_coords ],
915
+ )
916
+
917
+ # note: np.flip below because coords are in reverse order, which is how
918
+ # tiledb will return the results for the first query, but not second
919
+ assert_dict_arrays_equal (
920
+ A .multi_index [d1_coords .tolist (), np .flip (d2_coords .tolist ())],
921
+ A .multi_index [d1_coords , :],
922
+ )
923
+
924
+ slc = slice (0 , ncells - 1 , 2 )
925
+ assert_dict_arrays_equal (
926
+ A .multi_index [d1_coords [slc ].tolist (), :],
927
+ A .multi_index [d1_coords [slc ], :],
928
+ )
929
+ assert_dict_arrays_equal (
930
+ A .multi_index [:, d2_coords [slc ]], A .multi_index [:, d2_coords [slc ]]
931
+ )
0 commit comments