13
13
from concurrent .futures import Future
14
14
from itertools import zip_longest
15
15
from typing import (
16
+ TYPE_CHECKING ,
16
17
Any ,
17
18
Dict ,
18
19
List ,
38
39
_DictFilterSpec ,
39
40
)
40
41
42
+ if TYPE_CHECKING :
43
+ from ._read_iters import ManagedQuery
44
+
41
45
_JSONFilter = Union [str , Dict [str , Union [str , Union [int , float ]]]]
42
46
_JSONFilterList = Union [str , List [_JSONFilter ]]
43
47
@@ -465,48 +469,44 @@ def _cast_domainish(domainish: List[Any]) -> Tuple[Tuple[object, object], ...]:
465
469
return tuple (result )
466
470
467
471
468
- def _set_coords (
469
- mq : clib .ManagedQuery , sarr : clib .SOMAArray , coords : options .SparseNDCoords
470
- ) -> None :
472
+ def _set_coords (mq : ManagedQuery , coords : options .SparseNDCoords ) -> None :
471
473
if not is_nonstringy_sequence (coords ):
472
474
raise TypeError (
473
475
f"coords type { type (coords )} must be a regular sequence,"
474
476
" not str or bytes"
475
477
)
476
478
477
- if len (coords ) > len (sarr .dimension_names ):
479
+ if len (coords ) > len (mq . _array . _handle . _handle .dimension_names ):
478
480
raise ValueError (
479
481
f"coords ({ len (coords )} elements) must be shorter than ndim"
480
- f" ({ len (sarr .dimension_names )} )"
482
+ f" ({ len (mq . _array . _handle . _handle .dimension_names )} )"
481
483
)
482
484
483
485
for i , coord in enumerate (coords ):
484
- _set_coord (i , mq , sarr , coord )
486
+ _set_coord (i , mq , coord )
485
487
486
488
487
- def _set_coord (
488
- dim_idx : int , mq : clib .ManagedQuery , sarr : clib .SOMAArray , coord : object
489
- ) -> None :
489
+ def _set_coord (dim_idx : int , mq : ManagedQuery , coord : object ) -> None :
490
490
if coord is None :
491
491
return
492
492
493
- dim = sarr .schema .field (dim_idx )
494
- dom = _cast_domainish (sarr .domain ())[dim_idx ]
493
+ dim = mq . _array . _handle . _handle .schema .field (dim_idx )
494
+ dom = _cast_domainish (mq . _array . _handle . _handle .domain ())[dim_idx ]
495
495
496
496
if isinstance (coord , (str , bytes )):
497
- mq .set_dim_points_string_or_bytes (dim .name , [coord ])
497
+ mq ._handle . set_dim_points_string_or_bytes (dim .name , [coord ])
498
498
return
499
499
500
500
if isinstance (coord , (pa .Array , pa .ChunkedArray )):
501
- mq .set_dim_points_arrow (dim .name , coord )
501
+ mq ._handle . set_dim_points_arrow (dim .name , coord )
502
502
return
503
503
504
504
if isinstance (coord , (Sequence , np .ndarray )):
505
505
_set_coord_by_py_seq_or_np_array (mq , dim , coord )
506
506
return
507
507
508
508
if isinstance (coord , int ):
509
- mq .set_dim_points_int64 (dim .name , [coord ])
509
+ mq ._handle . set_dim_points_int64 (dim .name , [coord ])
510
510
return
511
511
512
512
# Note: slice(None, None) matches the is_slice_of part, unless we also check
@@ -521,11 +521,11 @@ def _set_coord(
521
521
if coord .stop is None :
522
522
# There's no way to specify "to infinity" for strings.
523
523
# We have to get the nonempty domain and use that as the end.\
524
- ned = _cast_domainish (sarr .non_empty_domain ())
524
+ ned = _cast_domainish (mq . _array . _handle . _handle .non_empty_domain ())
525
525
_ , stop = ned [dim_idx ]
526
526
else :
527
527
stop = coord .stop
528
- mq .set_dim_ranges_string_or_bytes (dim .name , [(start , stop )])
528
+ mq ._handle . set_dim_ranges_string_or_bytes (dim .name , [(start , stop )])
529
529
return
530
530
531
531
# Note: slice(None, None) matches the is_slice_of part, unless we also check
@@ -548,7 +548,7 @@ def _set_coord(
548
548
else :
549
549
istop = ts_dom [1 ].as_py ()
550
550
551
- mq .set_dim_ranges_int64 (dim .name , [(istart , istop )])
551
+ mq ._handle . set_dim_ranges_int64 (dim .name , [(istart , istop )])
552
552
return
553
553
554
554
if isinstance (coord , slice ):
@@ -562,7 +562,7 @@ def _set_coord(
562
562
563
563
564
564
def _set_coord_by_py_seq_or_np_array (
565
- mq : clib . ManagedQuery , dim : pa .Field , coord : object
565
+ mq : ManagedQuery , dim : pa .Field , coord : object
566
566
) -> None :
567
567
if isinstance (coord , np .ndarray ):
568
568
if coord .ndim != 1 :
@@ -571,7 +571,7 @@ def _set_coord_by_py_seq_or_np_array(
571
571
)
572
572
573
573
try :
574
- set_dim_points = getattr (mq , f"set_dim_points_{ dim .type } " )
574
+ set_dim_points = getattr (mq . _handle , f"set_dim_points_{ dim .type } " )
575
575
except AttributeError :
576
576
# We have to handle this type specially below
577
577
pass
@@ -580,7 +580,7 @@ def _set_coord_by_py_seq_or_np_array(
580
580
return
581
581
582
582
if pa_types_is_string_or_bytes (dim .type ):
583
- mq .set_dim_points_string_or_bytes (dim .name , coord )
583
+ mq ._handle . set_dim_points_string_or_bytes (dim .name , coord )
584
584
return
585
585
586
586
if pa .types .is_timestamp (dim .type ):
@@ -591,14 +591,14 @@ def _set_coord_by_py_seq_or_np_array(
591
591
icoord = [
592
592
int (e .astype ("int64" )) if isinstance (e , np .datetime64 ) else e for e in coord
593
593
]
594
- mq .set_dim_points_int64 (dim .name , icoord )
594
+ mq ._handle . set_dim_points_int64 (dim .name , icoord )
595
595
return
596
596
597
597
raise ValueError (f"unhandled type { dim .type } for index column named { dim .name } " )
598
598
599
599
600
600
def _set_coord_by_numeric_slice (
601
- mq : clib . ManagedQuery , dim : pa .Field , dom : Tuple [object , object ], coord : Slice [Any ]
601
+ mq : ManagedQuery , dim : pa .Field , dom : Tuple [object , object ], coord : Slice [Any ]
602
602
) -> None :
603
603
try :
604
604
lo_hi = slice_to_numeric_range (coord , dom )
@@ -609,7 +609,7 @@ def _set_coord_by_numeric_slice(
609
609
return
610
610
611
611
try :
612
- set_dim_range = getattr (mq , f"set_dim_ranges_{ dim .type } " )
612
+ set_dim_range = getattr (mq . _handle , f"set_dim_ranges_{ dim .type } " )
613
613
set_dim_range (dim .name , [lo_hi ])
614
614
return
615
615
except AttributeError :
0 commit comments