@@ -635,46 +635,43 @@ def test_use_numpy_query(self):
635
635
import numpy as np
636
636
637
637
with connections ["s2r1" ].cursor () as cursorWrapper :
638
- cursorWrapper .cursor .columnar = True
639
- cursorWrapper .cursor .use_numpy = True
640
- cursorWrapper .execute (sql )
641
- np .testing .assert_equal (
642
- cursorWrapper .fetchall (),
638
+ with cursorWrapper .cursor .set_query_args (columnar = True , use_numpy = True ) as cursor :
639
+ cursor .execute (sql )
640
+ np .testing .assert_equal (
641
+ cursor .fetchall (),
643
642
[
644
643
np .array ([np .datetime64 ('2022-01-01T01:00:05' ), np .datetime64 ('2022-01-01T01:00:05' ), np .datetime64 ('2022-01-01T01:00:05' )], dtype = 'datetime64[s]' ),
645
644
np .array ([0 , 1 , 2 ], dtype = np .uint64 ),
646
645
np .array ([0 , 2.5 , 5.0 ], dtype = np .float64 )
647
646
],
648
647
)
649
648
650
- cursorWrapper .execute (sql )
651
- np .testing .assert_equal (
652
- cursorWrapper .fetchmany (2 ),
653
- [
654
- np .array ([np .datetime64 ('2022-01-01T01:00:05' ), np .datetime64 ('2022-01-01T01:00:05' ), np .datetime64 ('2022-01-01T01:00:05' )], dtype = 'datetime64[s]' ),
655
- np .array ([0 , 1 , 2 ], dtype = np .uint64 ),
649
+ cursor .execute (sql )
650
+ np .testing .assert_equal (
651
+ cursor .fetchmany (2 ),
652
+ [
653
+ np .array ([np .datetime64 ('2022-01-01T01:00:05' ), np .datetime64 ('2022-01-01T01:00:05' ), np .datetime64 ('2022-01-01T01:00:05' )], dtype = 'datetime64[s]' ),
654
+ np .array ([0 , 1 , 2 ], dtype = np .uint64 ),
656
655
],
657
656
)
658
657
659
- actual_results = [
660
- r
661
- for results in iter (lambda : cursorWrapper .fetchmany (2 ), [])
662
- for r in results
663
- ]
664
- np .testing .assert_equal (
665
- actual_results ,
666
- [
667
- np .array ([0 , 2.5 , 5 ], dtype = np .float64 ),
668
- ],
669
- )
658
+ actual_results = [
659
+ r
660
+ for results in iter (lambda : cursor .fetchmany (2 ), [])
661
+ for r in results
662
+ ]
663
+ np .testing .assert_equal (
664
+ actual_results ,
665
+ [
666
+ np .array ([0 , 2.5 , 5 ], dtype = np .float64 ),
667
+ ],
668
+ )
670
669
671
- cursorWrapper .execute (sql )
672
- np .testing .assert_equal (
673
- cursorWrapper .fetchone (),
674
- np .array ([np .datetime64 ('2022-01-01T01:00:05' ), np .datetime64 ('2022-01-01T01:00:05' ), np .datetime64 ('2022-01-01T01:00:05' )], dtype = 'datetime64[s]' ),
675
- )
676
- cursorWrapper .cursor .columnar = False
677
- cursorWrapper .cursor .use_numpy = False
670
+ cursor .execute (sql )
671
+ np .testing .assert_equal (
672
+ cursor .fetchone (),
673
+ np .array ([np .datetime64 ('2022-01-01T01:00:05' ), np .datetime64 ('2022-01-01T01:00:05' ), np .datetime64 ('2022-01-01T01:00:05' )], dtype = 'datetime64[s]' ),
674
+ )
678
675
679
676
# These tests aren't conditional because it would require differentiating
680
677
# between MySQL+InnoDB and MySQL+MYISAM (something we currently can't do).
0 commit comments