-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathtest_formatting.py
More file actions
5098 lines (4958 loc) · 184 KB
/
Copy pathtest_formatting.py
File metadata and controls
5098 lines (4958 loc) · 184 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import numpy as np
import pytest
from graphblas import backend, dtypes, unary
from graphblas.core import formatting
from graphblas.core.formatting import CSS_STYLE
from .conftest import autocompute
from graphblas import Matrix, Scalar, Vector # isort:skip (for dask-graphblas)
try:
import pandas as pd
except ImportError: # pragma: no cover (import)
pd = None
if backend != "suitesparse":
pytest.skip("Formatting tests only work with suitesparse backend", allow_module_level=True)
def repr_html(x):
return x._repr_html_()
def _printer(text, name, repr_name, indent):
to_print = []
_print = to_print.append
indent = " " * indent
_print(f"{indent}assert {repr_name}({name}) == (")
lines = text.split("\n")
prev_line = ""
count = 0
in_style = False
is_style = False
for line in lines[:-1]:
if in_style:
if line.startswith("</style>"):
# line = f"f'{{CSS_STYLE}}'"
in_style = False
is_style = True
else:
continue # FLAKY COVERAGE
if repr_name == "repr_html" and line.startswith("<style>"):
prev_line = prev_line[:-1] # remove "\n"
in_style = True
continue
line = line + "\n"
if line == prev_line:
count += 1
else:
if count == 1:
_print(f"{indent} {prev_line!r}")
elif count > 1:
if to_print[-1][-1] == "+":
_print(f"{indent} {prev_line!r} * {count} +")
else:
_print(f"{indent} + {prev_line!r} * {count} +")
if is_style:
_print(f"{indent} f'{{CSS_STYLE}}'")
count = 0
is_style = False
else:
count = 1
prev_line = line
if count == 1:
_print(f"{indent} {prev_line!r}")
elif count > 1: # pragma: no cover
_print(f"{indent} {prev_line!r} * {count}")
_print(f"{indent} {lines[-1]!r}")
_print(f"{indent})")
print("\n".join(to_print))
def repr_printer(x, name="", indent=4):
return _printer(repr(x), name, "repr", indent)
def html_printer(x, name="", indent=4):
return _printer(repr_html(x), name, "repr_html", indent)
@pytest.fixture(autouse=True)
def _stable_repr_width(monkeypatch):
"""Pin terminal width so pandas-rendered reprs are deterministic.
Matrix/Vector reprs let pandas truncate columns to the terminal width, and
the expected strings assume 80. Under ``pytest -n`` workers inherit the
launching terminal's width, so a wide terminal would show extra columns.
"""
monkeypatch.setenv("COLUMNS", "80")
@pytest.fixture
def A():
return Matrix.from_coo([0, 0, 0], [0, 2, 4], [0, 1, 2], nrows=1, ncols=5, name="A_1")
@pytest.fixture
def B():
return Matrix.from_coo([0, 2, 4], [0, 0, 0], [10, 20, 30], nrows=5, ncols=1, name="B_1")
@pytest.fixture
def C():
return Matrix.from_coo(
[0, 9, 60, 69, 0, 9, 60, 69],
[4, 4, 4, 4, 72, 72, 72, 72],
[0, 2, 3, 4, 5, 6, 7, 8],
nrows=70,
ncols=77,
name="C",
)
@pytest.fixture
def D():
return Matrix.from_coo(
[0, 9, 60, 69],
[4, 4, 4, 4],
[True, False, True, False],
nrows=70,
name="D_skinny_in_one_dim",
)
@pytest.fixture
def v():
return Vector.from_coo([0, 2, 4], [0.0, 1.1, 2.2], name="v")
@pytest.fixture
def w():
return Vector.from_coo([0, 5, 64, 69], [1, 2, 3, 4], size=77, name="w")
@pytest.fixture
def s():
return Scalar.from_value(42, name="s_1")
@pytest.fixture
def t():
return Scalar(int, name="t")
def test_no_pandas_repr(A, C, v, w):
# This is a bit of a hack...
has_pandas_prev = formatting.has_pandas
formatting.has_pandas = False
try:
repr_printer(A, "A", indent=8)
assert repr(A) == (
'"A_1" nvals nrows ncols dtype format\n'
"gb.Matrix 3 1 5 INT64 bitmapr"
)
repr_printer(A.T, "A.T", indent=8)
assert repr(A.T) == (
'"A_1.T" nvals nrows ncols dtype format\n'
"gb.TransposedMatrix 3 5 1 INT64 bitmapc"
)
repr_printer(C.S, "C.S", indent=8)
assert repr(C.S) == (
'"C.S" nvals nrows ncols dtype format\n'
"StructuralMask\n"
"of gb.Matrix 8 70 77 INT64 hypercsr"
)
repr_printer(v, "v", indent=8)
assert repr(v) == (
'"v" nvals size dtype format\ngb.Vector 3 5 FP64 bitmap'
)
repr_printer(~w.V, "~w.V", indent=8)
assert repr(~w.V) == (
'"~w.V" nvals size dtype format\n'
"ComplementedValueMask\n"
"of gb.Vector 4 77 INT64 bitmap"
)
finally:
formatting.has_pandas = has_pandas_prev
@pytest.mark.skipif("not pd")
def test_matrix_repr_small(A, B):
repr_printer(A, "A")
assert repr(A) == (
'"A_1" nvals nrows ncols dtype format\n'
"gb.Matrix 3 1 5 INT64 bitmapr\n"
"----------------------------------------------\n"
" 0 1 2 3 4\n"
"0 0 1 2"
)
repr_printer(B, "B")
assert repr(B) == (
'"B_1" nvals nrows ncols dtype format\n'
"gb.Matrix 3 5 1 INT64 bitmapc\n"
"----------------------------------------------\n"
" 0\n"
"0 10\n"
"1 \n"
"2 20\n"
"3 \n"
"4 30"
)
repr_printer(B.T, "B.T")
assert repr(B.T) == (
'"B_1.T" nvals nrows ncols dtype format\n'
"gb.TransposedMatrix 3 1 5 INT64 bitmapr\n"
"--------------------------------------------------------\n"
" 0 1 2 3 4\n"
"0 10 20 30"
)
@pytest.mark.skipif("not pd")
def test_matrix_mask_repr_small(A):
repr_printer(A.S, "A.S")
assert repr(A.S) == (
'"A_1.S" nvals nrows ncols dtype format\n'
"StructuralMask\n"
"of gb.Matrix 3 1 5 INT64 bitmapr\n"
"---------------------------------------------------\n"
" 0 1 2 3 4\n"
"0 1 1 1"
)
repr_printer(A.V, "A.V")
assert repr(A.V) == (
'"A_1.V" nvals nrows ncols dtype format\n'
"ValueMask \n"
"of gb.Matrix 3 1 5 INT64 bitmapr\n"
"-------------------------------------------------\n"
" 0 1 2 3 4\n"
"0 0 1 1"
)
repr_printer(~A.S, "~A.S")
assert repr(~A.S) == (
'"~A_1.S" nvals nrows ncols dtype format\n'
"ComplementedStructuralMask\n"
"of gb.Matrix 3 1 5 INT64 bitmapr\n"
"---------------------------------------------------------------\n"
" 0 1 2 3 4\n"
"0 0 0 0"
)
repr_printer(~A.V, "~A.V")
assert repr(~A.V) == (
'"~A_1.V" nvals nrows ncols dtype format\n'
"ComplementedValueMask\n"
"of gb.Matrix 3 1 5 INT64 bitmapr\n"
"----------------------------------------------------------\n"
" 0 1 2 3 4\n"
"0 1 0 0"
)
@pytest.mark.skipif("not pd")
def test_matrix_repr_large(C, D):
with pd.option_context("display.max_columns", 24, "display.width", 100):
repr_printer(C, "C", indent=8)
assert repr(C) == (
'"C" nvals nrows ncols dtype format\n'
"gb.Matrix 8 70 77 INT64 hypercsr\n"
"-----------------------------------------------\n"
" 0 1 2 3 4 5 6 7 8 9 10 11 ... 65 66 67 68 69 70 71 72 73 74 75 76\n"
"0 0 ... 5 \n"
"1 ... \n"
"2 ... \n"
"3 ... \n"
"4 ... \n"
".. .. .. .. .. .. .. .. .. .. .. .. .. ... .. .. .. .. .. .. .. .. .. .. .. ..\n"
"65 ... \n"
"66 ... \n"
"67 ... \n"
"68 ... \n"
"69 4 ... 8 "
)
repr_printer(C.T, "C.T", indent=8)
assert repr(C.T) == (
'"C.T" nvals nrows ncols dtype format\n'
"gb.TransposedMatrix 8 77 70 INT64 hypercsc\n"
"---------------------------------------------------------\n"
" 0 1 2 3 4 5 6 7 8 9 10 11 ... 58 59 60 61 62 63 64 65 66 67 68 69\n"
"0 ... \n"
"1 ... \n"
"2 ... \n"
"3 ... \n"
"4 0 2 ... 3 4\n"
".. .. .. .. .. .. .. .. .. .. .. .. .. ... .. .. .. .. .. .. .. .. .. .. .. ..\n"
"72 5 6 ... 7 8\n"
"73 ... \n"
"74 ... \n"
"75 ... \n"
"76 ... "
)
repr_printer(D, "D", indent=8)
assert repr(D) == (
'"D_skinny_in_one_dim" nvals nrows ncols dtype format\n'
"gb.Matrix 4 70 5 BOOL hypercsr\n"
"-----------------------------------------------------------\n"
" 0 1 2 3 4\n"
"0 True\n"
"1 \n"
"2 \n"
"3 \n"
"4 \n"
".. .. .. .. .. ...\n"
"65 \n"
"66 \n"
"67 \n"
"68 \n"
"69 False"
)
repr_printer(D.T, "D.T", indent=8)
assert repr(D.T) == (
'"D_skinny_in_one_dim.T" nvals nrows ncols dtype format\n'
"gb.TransposedMatrix 4 5 70 BOOL hypercsc\n"
"-------------------------------------------------------------\n"
" 0 1 2 3 4 5 6 7 8 9 10 11 ... 58 59 60 61 62 63 64 65 66 67 68 69\n"
"0 ... \n"
"1 ... \n"
"2 ... \n"
"3 ... \n"
"4 True False ... True False"
)
@pytest.mark.skipif("not pd")
def test_matrix_mask_repr_large(C):
with pd.option_context("display.max_columns", 24, "display.width", 100):
repr_printer(C.S, "C.S", indent=8)
assert repr(C.S) == (
'"C.S" nvals nrows ncols dtype format\n'
"StructuralMask\n"
"of gb.Matrix 8 70 77 INT64 hypercsr\n"
"----------------------------------------------------\n"
" 0 1 2 3 4 5 6 7 8 9 10 11 ... 65 66 67 68 69 70 71 72 73 74 75 76\n"
"0 1 ... 1 \n"
"1 ... \n"
"2 ... \n"
"3 ... \n"
"4 ... \n"
".. .. .. .. .. .. .. .. .. .. .. .. .. ... .. .. .. .. .. .. .. .. .. .. .. ..\n"
"65 ... \n"
"66 ... \n"
"67 ... \n"
"68 ... \n"
"69 1 ... 1 "
)
repr_printer(C.V, "C.V", indent=8)
assert repr(C.V) == (
'"C.V" nvals nrows ncols dtype format\n'
"ValueMask \n"
"of gb.Matrix 8 70 77 INT64 hypercsr\n"
"--------------------------------------------------\n"
" 0 1 2 3 4 5 6 7 8 9 10 11 ... 65 66 67 68 69 70 71 72 73 74 75 76\n"
"0 0 ... 1 \n"
"1 ... \n"
"2 ... \n"
"3 ... \n"
"4 ... \n"
".. .. .. .. .. .. .. .. .. .. .. .. .. ... .. .. .. .. .. .. .. .. .. .. .. ..\n"
"65 ... \n"
"66 ... \n"
"67 ... \n"
"68 ... \n"
"69 1 ... 1 "
)
repr_printer(~C.S, "~C.S", indent=8)
assert repr(~C.S) == (
'"~C.S" nvals nrows ncols dtype format\n'
"ComplementedStructuralMask\n"
"of gb.Matrix 8 70 77 INT64 hypercsr\n"
"----------------------------------------------------------------\n"
" 0 1 2 3 4 5 6 7 8 9 10 11 ... 65 66 67 68 69 70 71 72 73 74 75 76\n"
"0 0 ... 0 \n"
"1 ... \n"
"2 ... \n"
"3 ... \n"
"4 ... \n"
".. .. .. .. .. .. .. .. .. .. .. .. .. ... .. .. .. .. .. .. .. .. .. .. .. ..\n"
"65 ... \n"
"66 ... \n"
"67 ... \n"
"68 ... \n"
"69 0 ... 0 "
)
repr_printer(~C.V, "~C.V", indent=8)
assert repr(~C.V) == (
'"~C.V" nvals nrows ncols dtype format\n'
"ComplementedValueMask\n"
"of gb.Matrix 8 70 77 INT64 hypercsr\n"
"-----------------------------------------------------------\n"
" 0 1 2 3 4 5 6 7 8 9 10 11 ... 65 66 67 68 69 70 71 72 73 74 75 76\n"
"0 1 ... 0 \n"
"1 ... \n"
"2 ... \n"
"3 ... \n"
"4 ... \n"
".. .. .. .. .. .. .. .. .. .. .. .. .. ... .. .. .. .. .. .. .. .. .. .. .. ..\n"
"65 ... \n"
"66 ... \n"
"67 ... \n"
"68 ... \n"
"69 0 ... 0 "
)
@pytest.mark.skipif("not pd")
def test_vector_repr_small(v):
repr_printer(v, "v")
assert repr(v) == (
'"v" nvals size dtype format\n'
"gb.Vector 3 5 FP64 bitmap\n"
"-------------------------------------\n"
"index 0 1 2 3 4\n"
"value 0.0 1.1 2.2"
)
@pytest.mark.skipif("not pd")
def test_vector_repr_large(w):
with pd.option_context("display.max_columns", 26, "display.width", 100):
repr_printer(w, "w", indent=8)
assert repr(w) == (
'"w" nvals size dtype format\n'
"gb.Vector 4 77 INT64 bitmap\n"
"-------------------------------------\n"
"index 0 1 2 3 4 5 6 7 8 9 10 11 12 ... 64 65 66 67 68 69 70 71 72 73 74 75 76\n"
"value 1 2 ... 3 4 "
)
@pytest.mark.skipif("not pd")
def test_vector_mask_repr_small(v):
repr_printer(v.S, "v.S")
assert repr(v.S) == (
'"v.S" nvals size dtype format\n'
"StructuralMask\n"
"of gb.Vector 3 5 FP64 bitmap\n"
"------------------------------------------\n"
"index 0 1 2 3 4\n"
"value 1 1 1"
)
repr_printer(v.V, "v.V")
assert repr(v.V) == (
'"v.V" nvals size dtype format\n'
"ValueMask \n"
"of gb.Vector 3 5 FP64 bitmap\n"
"----------------------------------------\n"
"index 0 1 2 3 4\n"
"value 0 1 1"
)
repr_printer(~v.S, "~v.S")
assert repr(~v.S) == (
'"~v.S" nvals size dtype format\n'
"ComplementedStructuralMask\n"
"of gb.Vector 3 5 FP64 bitmap\n"
"------------------------------------------------------\n"
"index 0 1 2 3 4\n"
"value 0 0 0"
)
repr_printer(~v.V, "~v.V")
assert repr(~v.V) == (
'"~v.V" nvals size dtype format\n'
"ComplementedValueMask\n"
"of gb.Vector 3 5 FP64 bitmap\n"
"-------------------------------------------------\n"
"index 0 1 2 3 4\n"
"value 1 0 0"
)
@pytest.mark.skipif("not pd")
def test_vector_mask_repr_large(w):
with pd.option_context("display.max_columns", 26, "display.width", 100):
repr_printer(w.S, "w.S", indent=8)
assert repr(w.S) == (
'"w.S" nvals size dtype format\n'
"StructuralMask\n"
"of gb.Vector 4 77 INT64 bitmap\n"
"------------------------------------------\n"
"index 0 1 2 3 4 5 6 7 8 9 10 11 12 ... 64 65 66 67 68 69 70 71 72 73 74 75 76\n"
"value 1 1 ... 1 1 "
)
repr_printer(w.V, "w.V", indent=8)
assert repr(w.V) == (
'"w.V" nvals size dtype format\n'
"ValueMask \n"
"of gb.Vector 4 77 INT64 bitmap\n"
"----------------------------------------\n"
"index 0 1 2 3 4 5 6 7 8 9 10 11 12 ... 64 65 66 67 68 69 70 71 72 73 74 75 76\n"
"value 1 1 ... 1 1 "
)
repr_printer(~w.S, "~w.S", indent=8)
assert repr(~w.S) == (
'"~w.S" nvals size dtype format\n'
"ComplementedStructuralMask\n"
"of gb.Vector 4 77 INT64 bitmap\n"
"------------------------------------------------------\n"
"index 0 1 2 3 4 5 6 7 8 9 10 11 12 ... 64 65 66 67 68 69 70 71 72 73 74 75 76\n"
"value 0 0 ... 0 0 "
)
repr_printer(~w.V, "~w.V", indent=8)
assert repr(~w.V) == (
'"~w.V" nvals size dtype format\n'
"ComplementedValueMask\n"
"of gb.Vector 4 77 INT64 bitmap\n"
"-------------------------------------------------\n"
"index 0 1 2 3 4 5 6 7 8 9 10 11 12 ... 64 65 66 67 68 69 70 71 72 73 74 75 76\n"
"value 0 0 ... 0 0 "
)
def test_scalar_repr(s, t):
repr_printer(s, "s")
assert repr(s) == ('"s_1" value dtype\ngb.Scalar 42 INT64')
assert repr(t) == ('"t" value dtype\ngb.Scalar None INT64')
def test_no_pandas_repr_html(A, C, v, w):
# This is a bit of a hack...
has_pandas_prev = formatting.has_pandas
formatting.has_pandas = False
try:
html_printer(A, "A", indent=8)
assert repr_html(A) == (
"<div>"
f"{CSS_STYLE}"
'<details class="gb-arg-details"><summary class="gb-arg-summary"><tt>A<sub>1</sub></tt><div>\n'
'<table class="gb-info-table">\n'
" <tr>\n"
' <td rowspan="2" class="gb-info-name-cell"><pre>gb.Matrix</pre></td>\n'
" <td><pre>nvals</pre></td>\n"
" <td><pre>nrows</pre></td>\n"
" <td><pre>ncols</pre></td>\n"
" <td><pre>dtype</pre></td>\n"
" <td><pre>format</pre></td>\n"
" </tr>\n"
" <tr>\n"
" <td>3</td>\n"
" <td>1</td>\n"
" <td>5</td>\n"
" <td>INT64</td>\n"
" <td>bitmapr</td>\n"
" </tr>\n"
"</table>\n"
"</div>\n"
"</summary><em>(Install</em> <tt>pandas</tt> <em>to see a preview of the data)</em></details></div>"
)
html_printer(A.T, "A.T", indent=8)
assert repr_html(A.T) == (
"<div>"
f"{CSS_STYLE}"
'<details class="gb-arg-details"><summary class="gb-arg-summary"><tt>A<sub>1</sub>.T</tt><div>\n'
'<table class="gb-info-table">\n'
" <tr>\n"
' <td rowspan="2" class="gb-info-name-cell"><pre>gb.TransposedMatrix</pre></td>\n'
" <td><pre>nvals</pre></td>\n"
" <td><pre>nrows</pre></td>\n"
" <td><pre>ncols</pre></td>\n"
" <td><pre>dtype</pre></td>\n"
" <td><pre>format</pre></td>\n"
" </tr>\n"
" <tr>\n"
" <td>3</td>\n"
" <td>5</td>\n"
" <td>1</td>\n"
" <td>INT64</td>\n"
" <td>bitmapc</td>\n"
" </tr>\n"
"</table>\n"
"</div>\n"
"</summary><em>(Install</em> <tt>pandas</tt> <em>to see a preview of the data)</em></details></div>"
)
html_printer(C.S, "C.S", indent=8)
assert repr_html(C.S) == (
"<div>"
f"{CSS_STYLE}"
'<details class="gb-arg-details"><summary class="gb-arg-summary"><tt>C.S</tt><div>\n'
'<table class="gb-info-table">\n'
" <tr>\n"
' <td rowspan="2" class="gb-info-name-cell"><pre>StructuralMask\n'
"of\n"
"gb.Matrix</pre></td>\n"
" <td><pre>nvals</pre></td>\n"
" <td><pre>nrows</pre></td>\n"
" <td><pre>ncols</pre></td>\n"
" <td><pre>dtype</pre></td>\n"
" <td><pre>format</pre></td>\n"
" </tr>\n"
" <tr>\n"
" <td>8</td>\n"
" <td>70</td>\n"
" <td>77</td>\n"
" <td>INT64</td>\n"
" <td>hypercsr</td>\n"
" </tr>\n"
"</table>\n"
"</div>\n"
"</summary><em>(Install</em> <tt>pandas</tt> <em>to see a preview of the data)</em></details></div>"
)
html_printer(v, "v", indent=8)
assert repr_html(v) == (
"<div>"
f"{CSS_STYLE}"
'<details class="gb-arg-details"><summary class="gb-arg-summary"><tt>v</tt><div>\n'
'<table class="gb-info-table">\n'
" <tr>\n"
' <td rowspan="2" class="gb-info-name-cell"><pre>gb.Vector</pre></td>\n'
" <td><pre>nvals</pre></td>\n"
" <td><pre>size</pre></td>\n"
" <td><pre>dtype</pre></td>\n"
" <td><pre>format</pre></td>\n"
" </tr>\n"
" <tr>\n"
" <td>3</td>\n"
" <td>5</td>\n"
" <td>FP64</td>\n"
" <td>bitmap</td>\n"
" </tr>\n"
"</table>\n"
"</div>\n"
"</summary><em>(Install</em> <tt>pandas</tt> <em>to see a preview of the data)</em></details></div>"
)
html_printer(~w.V, "~w.V", indent=8)
assert repr_html(~w.V) == (
"<div>"
f"{CSS_STYLE}"
'<details class="gb-arg-details"><summary class="gb-arg-summary"><tt>~w.V</tt><div>\n'
'<table class="gb-info-table">\n'
" <tr>\n"
' <td rowspan="2" class="gb-info-name-cell"><pre>ComplementedValueMask\n'
"of\n"
"gb.Vector</pre></td>\n"
" <td><pre>nvals</pre></td>\n"
" <td><pre>size</pre></td>\n"
" <td><pre>dtype</pre></td>\n"
" <td><pre>format</pre></td>\n"
" </tr>\n"
" <tr>\n"
" <td>4</td>\n"
" <td>77</td>\n"
" <td>INT64</td>\n"
" <td>bitmap</td>\n"
" </tr>\n"
"</table>\n"
"</div>\n"
"</summary><em>(Install</em> <tt>pandas</tt> <em>to see a preview of the data)</em></details></div>"
)
finally:
formatting.has_pandas = has_pandas_prev
@pytest.mark.skipif("not pd")
def test_matrix_repr_html_small(A, B):
html_printer(A, "A")
assert repr_html(A) == (
"<div>"
f"{CSS_STYLE}"
'<details open class="gb-arg-details"><summary class="gb-arg-summary"><tt>A<sub>1</sub></tt><div>\n'
'<table class="gb-info-table">\n'
" <tr>\n"
' <td rowspan="2" class="gb-info-name-cell"><pre>gb.Matrix</pre></td>\n'
" <td><pre>nvals</pre></td>\n"
" <td><pre>nrows</pre></td>\n"
" <td><pre>ncols</pre></td>\n"
" <td><pre>dtype</pre></td>\n"
" <td><pre>format</pre></td>\n"
" </tr>\n"
" <tr>\n"
" <td>3</td>\n"
" <td>1</td>\n"
" <td>5</td>\n"
" <td>INT64</td>\n"
" <td>bitmapr</td>\n"
" </tr>\n"
"</table>\n"
"</div>\n"
"</summary><div>\n"
"<style scoped>\n"
" .dataframe tbody tr th:only-of-type {\n"
" vertical-align: middle;\n"
" }\n"
"\n"
" .dataframe tbody tr th {\n"
" vertical-align: top;\n"
" }\n"
"\n"
" .dataframe thead th {\n"
" text-align: right;\n"
" }\n"
"</style>\n"
'<table border="1" class="dataframe">\n'
" <thead>\n"
' <tr style="text-align: right;">\n'
" <th></th>\n"
" <th>0</th>\n"
" <th>1</th>\n"
" <th>2</th>\n"
" <th>3</th>\n"
" <th>4</th>\n"
" </tr>\n"
" </thead>\n"
" <tbody>\n"
" <tr>\n"
" <th>0</th>\n"
" <td>0</td>\n"
" <td></td>\n"
" <td>1</td>\n"
" <td></td>\n"
" <td>2</td>\n"
" </tr>\n"
" </tbody>\n"
"</table>\n"
"</div></details></div>"
)
html_printer(B, "B")
assert repr_html(B) == (
"<div>"
f"{CSS_STYLE}"
'<details open class="gb-arg-details"><summary class="gb-arg-summary"><tt>B<sub>1</sub></tt><div>\n'
'<table class="gb-info-table">\n'
" <tr>\n"
' <td rowspan="2" class="gb-info-name-cell"><pre>gb.Matrix</pre></td>\n'
" <td><pre>nvals</pre></td>\n"
" <td><pre>nrows</pre></td>\n"
" <td><pre>ncols</pre></td>\n"
" <td><pre>dtype</pre></td>\n"
" <td><pre>format</pre></td>\n"
" </tr>\n"
" <tr>\n"
" <td>3</td>\n"
" <td>5</td>\n"
" <td>1</td>\n"
" <td>INT64</td>\n"
" <td>bitmapc</td>\n"
" </tr>\n"
"</table>\n"
"</div>\n"
"</summary><div>\n"
"<style scoped>\n"
" .dataframe tbody tr th:only-of-type {\n"
" vertical-align: middle;\n"
" }\n"
"\n"
" .dataframe tbody tr th {\n"
" vertical-align: top;\n"
" }\n"
"\n"
" .dataframe thead th {\n"
" text-align: right;\n"
" }\n"
"</style>\n"
'<table border="1" class="dataframe">\n'
" <thead>\n"
' <tr style="text-align: right;">\n'
" <th></th>\n"
" <th>0</th>\n"
" </tr>\n"
" </thead>\n"
" <tbody>\n"
" <tr>\n"
" <th>0</th>\n"
" <td>10</td>\n"
" </tr>\n"
" <tr>\n"
" <th>1</th>\n"
" <td></td>\n"
" </tr>\n"
" <tr>\n"
" <th>2</th>\n"
" <td>20</td>\n"
" </tr>\n"
" <tr>\n"
" <th>3</th>\n"
" <td></td>\n"
" </tr>\n"
" <tr>\n"
" <th>4</th>\n"
" <td>30</td>\n"
" </tr>\n"
" </tbody>\n"
"</table>\n"
"</div></details></div>"
)
html_printer(B.T, "B.T")
assert repr_html(B.T) == (
"<div>"
f"{CSS_STYLE}"
'<details open class="gb-arg-details"><summary class="gb-arg-summary"><tt>B<sub>1</sub>.T</tt><div>\n'
'<table class="gb-info-table">\n'
" <tr>\n"
' <td rowspan="2" class="gb-info-name-cell"><pre>gb.TransposedMatrix</pre></td>\n'
" <td><pre>nvals</pre></td>\n"
" <td><pre>nrows</pre></td>\n"
" <td><pre>ncols</pre></td>\n"
" <td><pre>dtype</pre></td>\n"
" <td><pre>format</pre></td>\n"
" </tr>\n"
" <tr>\n"
" <td>3</td>\n"
" <td>1</td>\n"
" <td>5</td>\n"
" <td>INT64</td>\n"
" <td>bitmapr</td>\n"
" </tr>\n"
"</table>\n"
"</div>\n"
"</summary><div>\n"
"<style scoped>\n"
" .dataframe tbody tr th:only-of-type {\n"
" vertical-align: middle;\n"
" }\n"
"\n"
" .dataframe tbody tr th {\n"
" vertical-align: top;\n"
" }\n"
"\n"
" .dataframe thead th {\n"
" text-align: right;\n"
" }\n"
"</style>\n"
'<table border="1" class="dataframe">\n'
" <thead>\n"
' <tr style="text-align: right;">\n'
" <th></th>\n"
" <th>0</th>\n"
" <th>1</th>\n"
" <th>2</th>\n"
" <th>3</th>\n"
" <th>4</th>\n"
" </tr>\n"
" </thead>\n"
" <tbody>\n"
" <tr>\n"
" <th>0</th>\n"
" <td>10</td>\n"
" <td></td>\n"
" <td>20</td>\n"
" <td></td>\n"
" <td>30</td>\n"
" </tr>\n"
" </tbody>\n"
"</table>\n"
"</div></details></div>"
)
@pytest.mark.skipif("not pd")
def test_matrix_mask_repr_html_small(A):
html_printer(A.S, "A.S")
assert repr_html(A.S) == (
"<div>"
f"{CSS_STYLE}"
'<details open class="gb-arg-details"><summary class="gb-arg-summary"><tt>A<sub>1</sub>.S</tt><div>\n'
'<table class="gb-info-table">\n'
" <tr>\n"
' <td rowspan="2" class="gb-info-name-cell"><pre>StructuralMask\n'
"of\n"
"gb.Matrix</pre></td>\n"
" <td><pre>nvals</pre></td>\n"
" <td><pre>nrows</pre></td>\n"
" <td><pre>ncols</pre></td>\n"
" <td><pre>dtype</pre></td>\n"
" <td><pre>format</pre></td>\n"
" </tr>\n"
" <tr>\n"
" <td>3</td>\n"
" <td>1</td>\n"
" <td>5</td>\n"
" <td>INT64</td>\n"
" <td>bitmapr</td>\n"
" </tr>\n"
"</table>\n"
"</div>\n"
"</summary><div>\n"
"<style scoped>\n"
" .dataframe tbody tr th:only-of-type {\n"
" vertical-align: middle;\n"
" }\n"
"\n"
" .dataframe tbody tr th {\n"
" vertical-align: top;\n"
" }\n"
"\n"
" .dataframe thead th {\n"
" text-align: right;\n"
" }\n"
"</style>\n"
'<table border="1" class="dataframe">\n'
" <thead>\n"
' <tr style="text-align: right;">\n'
" <th></th>\n"
" <th>0</th>\n"
" <th>1</th>\n"
" <th>2</th>\n"
" <th>3</th>\n"
" <th>4</th>\n"
" </tr>\n"
" </thead>\n"
" <tbody>\n"
" <tr>\n"
" <th>0</th>\n"
" <td>1</td>\n"
" <td></td>\n"
" <td>1</td>\n"
" <td></td>\n"
" <td>1</td>\n"
" </tr>\n"
" </tbody>\n"
"</table>\n"
"</div></details></div>"
)
html_printer(A.V, "A.V")
assert repr_html(A.V) == (
"<div>"
f"{CSS_STYLE}"
'<details open class="gb-arg-details"><summary class="gb-arg-summary"><tt>A<sub>1</sub>.V</tt><div>\n'
'<table class="gb-info-table">\n'
" <tr>\n"
' <td rowspan="2" class="gb-info-name-cell"><pre>ValueMask\n'
"of\n"
"gb.Matrix</pre></td>\n"
" <td><pre>nvals</pre></td>\n"
" <td><pre>nrows</pre></td>\n"
" <td><pre>ncols</pre></td>\n"
" <td><pre>dtype</pre></td>\n"
" <td><pre>format</pre></td>\n"
" </tr>\n"
" <tr>\n"
" <td>3</td>\n"
" <td>1</td>\n"
" <td>5</td>\n"
" <td>INT64</td>\n"
" <td>bitmapr</td>\n"
" </tr>\n"
"</table>\n"
"</div>\n"
"</summary><div>\n"
"<style scoped>\n"
" .dataframe tbody tr th:only-of-type {\n"
" vertical-align: middle;\n"
" }\n"
"\n"
" .dataframe tbody tr th {\n"
" vertical-align: top;\n"
" }\n"
"\n"
" .dataframe thead th {\n"
" text-align: right;\n"
" }\n"
"</style>\n"
'<table border="1" class="dataframe">\n'
" <thead>\n"
' <tr style="text-align: right;">\n'
" <th></th>\n"
" <th>0</th>\n"
" <th>1</th>\n"
" <th>2</th>\n"
" <th>3</th>\n"
" <th>4</th>\n"
" </tr>\n"
" </thead>\n"
" <tbody>\n"
" <tr>\n"
" <th>0</th>\n"
" <td>0</td>\n"
" <td></td>\n"
" <td>1</td>\n"
" <td></td>\n"
" <td>1</td>\n"
" </tr>\n"
" </tbody>\n"
"</table>\n"
"</div></details></div>"
)
html_printer(~A.S, "~A.S")
assert repr_html(~A.S) == (
"<div>"
f"{CSS_STYLE}"
'<details open class="gb-arg-details"><summary class="gb-arg-summary"><tt>~A<sub>1</sub>.S</tt><div>\n'
'<table class="gb-info-table">\n'
" <tr>\n"
' <td rowspan="2" class="gb-info-name-cell"><pre>ComplementedStructuralMask\n'
"of\n"
"gb.Matrix</pre></td>\n"
" <td><pre>nvals</pre></td>\n"
" <td><pre>nrows</pre></td>\n"
" <td><pre>ncols</pre></td>\n"
" <td><pre>dtype</pre></td>\n"
" <td><pre>format</pre></td>\n"
" </tr>\n"
" <tr>\n"
" <td>3</td>\n"
" <td>1</td>\n"
" <td>5</td>\n"
" <td>INT64</td>\n"
" <td>bitmapr</td>\n"
" </tr>\n"
"</table>\n"
"</div>\n"