forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_arrow.py
1911 lines (1756 loc) · 72.1 KB
/
test_arrow.py
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
"""
This file contains a minimal set of tests for compliance with the extension
array interface test suite, and should contain no other tests.
The test suite for the full functionality of the array is located in
`pandas/tests/arrays/`.
The tests in this file are inherited from the BaseExtensionTests, and only
minimal tweaks should be applied to get the tests passing (by overwriting a
parent method).
Additional tests should either be added to one of the BaseExtensionTests
classes (if they are relevant for the extension interface for all dtypes), or
be added to the array-specific tests in `pandas/tests/arrays/`.
"""
from datetime import (
date,
datetime,
time,
timedelta,
)
import numpy as np
import pytest
from pandas.compat import (
pa_version_under2p0,
pa_version_under3p0,
pa_version_under4p0,
pa_version_under6p0,
pa_version_under8p0,
pa_version_under9p0,
)
import pandas as pd
import pandas._testing as tm
from pandas.tests.extension import base
pa = pytest.importorskip("pyarrow", minversion="1.0.1")
from pandas.core.arrays.arrow.dtype import ArrowDtype # isort:skip
@pytest.fixture(params=tm.ALL_PYARROW_DTYPES, ids=str)
def dtype(request):
return ArrowDtype(pyarrow_dtype=request.param)
@pytest.fixture
def data(dtype):
pa_dtype = dtype.pyarrow_dtype
if pa.types.is_boolean(pa_dtype):
data = [True, False] * 4 + [None] + [True, False] * 44 + [None] + [True, False]
elif pa.types.is_floating(pa_dtype):
data = [1.0, 0.0] * 4 + [None] + [-2.0, -1.0] * 44 + [None] + [0.5, 99.5]
elif pa.types.is_signed_integer(pa_dtype):
data = [1, 0] * 4 + [None] + [-2, -1] * 44 + [None] + [1, 99]
elif pa.types.is_unsigned_integer(pa_dtype):
data = [1, 0] * 4 + [None] + [2, 1] * 44 + [None] + [1, 99]
elif pa.types.is_date(pa_dtype):
data = (
[date(2022, 1, 1), date(1999, 12, 31)] * 4
+ [None]
+ [date(2022, 1, 1), date(2022, 1, 1)] * 44
+ [None]
+ [date(1999, 12, 31), date(1999, 12, 31)]
)
elif pa.types.is_timestamp(pa_dtype):
data = (
[datetime(2020, 1, 1, 1, 1, 1, 1), datetime(1999, 1, 1, 1, 1, 1, 1)] * 4
+ [None]
+ [datetime(2020, 1, 1, 1), datetime(1999, 1, 1, 1)] * 44
+ [None]
+ [datetime(2020, 1, 1), datetime(1999, 1, 1)]
)
elif pa.types.is_duration(pa_dtype):
data = (
[timedelta(1), timedelta(1, 1)] * 4
+ [None]
+ [timedelta(-1), timedelta(0)] * 44
+ [None]
+ [timedelta(-10), timedelta(10)]
)
elif pa.types.is_time(pa_dtype):
data = (
[time(12, 0), time(0, 12)] * 4
+ [None]
+ [time(0, 0), time(1, 1)] * 44
+ [None]
+ [time(0, 5), time(5, 0)]
)
else:
raise NotImplementedError
return pd.array(data, dtype=dtype)
@pytest.fixture
def data_missing(data):
"""Length-2 array with [NA, Valid]"""
return type(data)._from_sequence([None, data[0]])
@pytest.fixture(params=["data", "data_missing"])
def all_data(request, data, data_missing):
"""Parametrized fixture returning 'data' or 'data_missing' integer arrays.
Used to test dtype conversion with and without missing values.
"""
if request.param == "data":
return data
elif request.param == "data_missing":
return data_missing
@pytest.fixture
def data_for_grouping(dtype):
"""
Data for factorization, grouping, and unique tests.
Expected to be like [B, B, NA, NA, A, A, B, C]
Where A < B < C and NA is missing
"""
pa_dtype = dtype.pyarrow_dtype
if pa.types.is_boolean(pa_dtype):
A = False
B = True
C = True
elif pa.types.is_floating(pa_dtype):
A = -1.1
B = 0.0
C = 1.1
elif pa.types.is_signed_integer(pa_dtype):
A = -1
B = 0
C = 1
elif pa.types.is_unsigned_integer(pa_dtype):
A = 0
B = 1
C = 10
elif pa.types.is_date(pa_dtype):
A = date(1999, 12, 31)
B = date(2010, 1, 1)
C = date(2022, 1, 1)
elif pa.types.is_timestamp(pa_dtype):
A = datetime(1999, 1, 1, 1, 1, 1, 1)
B = datetime(2020, 1, 1)
C = datetime(2020, 1, 1, 1)
elif pa.types.is_duration(pa_dtype):
A = timedelta(-1)
B = timedelta(0)
C = timedelta(1, 4)
elif pa.types.is_time(pa_dtype):
A = time(0, 0)
B = time(0, 12)
C = time(12, 12)
else:
raise NotImplementedError
return pd.array([B, B, None, None, A, A, B, C], dtype=dtype)
@pytest.fixture
def data_for_sorting(data_for_grouping):
"""
Length-3 array with a known sort order.
This should be three items [B, C, A] with
A < B < C
"""
return type(data_for_grouping)._from_sequence(
[data_for_grouping[0], data_for_grouping[7], data_for_grouping[4]]
)
@pytest.fixture
def data_missing_for_sorting(data_for_grouping):
"""
Length-3 array with a known sort order.
This should be three items [B, NA, A] with
A < B and NA missing.
"""
return type(data_for_grouping)._from_sequence(
[data_for_grouping[0], data_for_grouping[2], data_for_grouping[4]]
)
@pytest.fixture
def data_for_twos(data):
"""Length-100 array in which all the elements are two."""
pa_dtype = data.dtype.pyarrow_dtype
if pa.types.is_integer(pa_dtype) or pa.types.is_floating(pa_dtype):
return pd.array([2] * 100, dtype=data.dtype)
# tests will be xfailed where 2 is not a valid scalar for pa_dtype
return data
@pytest.fixture
def na_value():
"""The scalar missing value for this type. Default 'None'"""
return pd.NA
class TestBaseCasting(base.BaseCastingTests):
pass
class TestConstructors(base.BaseConstructorsTests):
def test_from_dtype(self, data, request):
pa_dtype = data.dtype.pyarrow_dtype
if pa.types.is_timestamp(pa_dtype) and pa_dtype.tz:
if pa_version_under2p0:
request.node.add_marker(
pytest.mark.xfail(
reason=f"timestamp data with tz={pa_dtype.tz} "
"converted to integer when pyarrow < 2.0",
)
)
else:
request.node.add_marker(
pytest.mark.xfail(
raises=NotImplementedError,
reason=f"pyarrow.type_for_alias cannot infer {pa_dtype}",
)
)
super().test_from_dtype(data)
@pytest.mark.xfail(
raises=NotImplementedError, reason="pyarrow.ChunkedArray backing is 1D."
)
class TestDim2Compat(base.Dim2CompatTests):
pass
@pytest.mark.xfail(
raises=NotImplementedError, reason="pyarrow.ChunkedArray backing is 1D."
)
class TestNDArrayBacked2D(base.NDArrayBacked2DTests):
pass
class TestGetitemTests(base.BaseGetitemTests):
@pytest.mark.xfail(
reason=(
"data.dtype.type return pyarrow.DataType "
"but this (intentionally) returns "
"Python scalars or pd.Na"
)
)
def test_getitem_scalar(self, data):
super().test_getitem_scalar(data)
def test_take_series(self, request, data):
tz = getattr(data.dtype.pyarrow_dtype, "tz", None)
unit = getattr(data.dtype.pyarrow_dtype, "unit", None)
bad_units = ["ns"]
if pa_version_under2p0:
bad_units.extend(["s", "ms", "us"])
if pa_version_under3p0 and tz not in (None, "UTC") and unit in bad_units:
request.node.add_marker(
pytest.mark.xfail(
reason=(
f"Not supported by pyarrow < 3.0 "
f"with timestamp type {tz} and {unit}"
)
)
)
super().test_take_series(data)
def test_reindex(self, request, data, na_value):
tz = getattr(data.dtype.pyarrow_dtype, "tz", None)
unit = getattr(data.dtype.pyarrow_dtype, "unit", None)
bad_units = ["ns"]
if pa_version_under2p0:
bad_units.extend(["s", "ms", "us"])
if pa_version_under3p0 and tz not in (None, "UTC") and unit in bad_units:
request.node.add_marker(
pytest.mark.xfail(
reason=(
f"Not supported by pyarrow < 3.0 "
f"with timestamp type {tz} and {unit}"
)
)
)
super().test_reindex(data, na_value)
def test_loc_iloc_frame_single_dtype(self, request, using_array_manager, data):
tz = getattr(data.dtype.pyarrow_dtype, "tz", None)
unit = getattr(data.dtype.pyarrow_dtype, "unit", None)
bad_units = ["ns"]
if pa_version_under2p0:
bad_units.extend(["s", "ms", "us"])
if (
pa_version_under3p0
and not using_array_manager
and tz not in (None, "UTC")
and unit in bad_units
):
request.node.add_marker(
pytest.mark.xfail(
reason=(
f"Not supported by pyarrow < 3.0 "
f"with timestamp type {tz} and {unit}"
)
)
)
super().test_loc_iloc_frame_single_dtype(data)
class TestBaseGroupby(base.BaseGroupbyTests):
def test_groupby_agg_extension(self, data_for_grouping, request):
tz = getattr(data_for_grouping.dtype.pyarrow_dtype, "tz", None)
if pa_version_under2p0 and tz not in (None, "UTC"):
request.node.add_marker(
pytest.mark.xfail(
reason=f"Not supported by pyarrow < 2.0 with timestamp type {tz}."
)
)
super().test_groupby_agg_extension(data_for_grouping)
def test_groupby_extension_no_sort(self, data_for_grouping, request):
pa_dtype = data_for_grouping.dtype.pyarrow_dtype
if pa.types.is_boolean(pa_dtype):
request.node.add_marker(
pytest.mark.xfail(
reason=f"{pa_dtype} only has 2 unique possible values",
)
)
elif pa.types.is_duration(pa_dtype):
request.node.add_marker(
pytest.mark.xfail(
raises=pa.ArrowNotImplementedError,
reason=f"pyarrow doesn't support factorizing {pa_dtype}",
)
)
elif pa.types.is_date(pa_dtype) or (
pa.types.is_timestamp(pa_dtype) and pa_dtype.tz is None
):
request.node.add_marker(
pytest.mark.xfail(
raises=AttributeError,
reason="GH 34986",
)
)
super().test_groupby_extension_no_sort(data_for_grouping)
def test_groupby_extension_transform(self, data_for_grouping, request):
pa_dtype = data_for_grouping.dtype.pyarrow_dtype
if pa.types.is_boolean(pa_dtype):
request.node.add_marker(
pytest.mark.xfail(
reason=f"{pa_dtype} only has 2 unique possible values",
)
)
elif pa.types.is_duration(pa_dtype):
request.node.add_marker(
pytest.mark.xfail(
raises=pa.ArrowNotImplementedError,
reason=f"pyarrow doesn't support factorizing {pa_dtype}",
)
)
super().test_groupby_extension_transform(data_for_grouping)
def test_groupby_extension_apply(
self, data_for_grouping, groupby_apply_op, request
):
pa_dtype = data_for_grouping.dtype.pyarrow_dtype
# Is there a better way to get the "series" ID for groupby_apply_op?
is_series = "series" in request.node.nodeid
is_object = "object" in request.node.nodeid
if pa.types.is_duration(pa_dtype):
request.node.add_marker(
pytest.mark.xfail(
raises=pa.ArrowNotImplementedError,
reason=f"pyarrow doesn't support factorizing {pa_dtype}",
)
)
elif pa.types.is_date(pa_dtype) or (
pa.types.is_timestamp(pa_dtype) and pa_dtype.tz is None
):
if is_object:
request.node.add_marker(
pytest.mark.xfail(
raises=TypeError,
reason="GH 47514: _concat_datetime expects axis arg.",
)
)
elif not is_series:
request.node.add_marker(
pytest.mark.xfail(
raises=AttributeError,
reason="GH 34986",
)
)
super().test_groupby_extension_apply(data_for_grouping, groupby_apply_op)
def test_in_numeric_groupby(self, data_for_grouping, request):
pa_dtype = data_for_grouping.dtype.pyarrow_dtype
if pa.types.is_integer(pa_dtype) or pa.types.is_floating(pa_dtype):
request.node.add_marker(
pytest.mark.xfail(
reason="ArrowExtensionArray doesn't support .sum() yet.",
)
)
super().test_in_numeric_groupby(data_for_grouping)
@pytest.mark.parametrize("as_index", [True, False])
def test_groupby_extension_agg(self, as_index, data_for_grouping, request):
pa_dtype = data_for_grouping.dtype.pyarrow_dtype
if pa.types.is_boolean(pa_dtype):
request.node.add_marker(
pytest.mark.xfail(
raises=ValueError,
reason=f"{pa_dtype} only has 2 unique possible values",
)
)
elif pa.types.is_duration(pa_dtype):
request.node.add_marker(
pytest.mark.xfail(
raises=pa.ArrowNotImplementedError,
reason=f"pyarrow doesn't support factorizing {pa_dtype}",
)
)
elif as_index is True and (
pa.types.is_date(pa_dtype)
or (pa.types.is_timestamp(pa_dtype) and pa_dtype.tz is None)
):
request.node.add_marker(
pytest.mark.xfail(
raises=AttributeError,
reason="GH 34986",
)
)
super().test_groupby_extension_agg(as_index, data_for_grouping)
class TestBaseDtype(base.BaseDtypeTests):
def test_construct_from_string_own_name(self, dtype, request):
pa_dtype = dtype.pyarrow_dtype
if pa.types.is_timestamp(pa_dtype) and pa_dtype.tz is not None:
request.node.add_marker(
pytest.mark.xfail(
raises=NotImplementedError,
reason=f"pyarrow.type_for_alias cannot infer {pa_dtype}",
)
)
super().test_construct_from_string_own_name(dtype)
def test_is_dtype_from_name(self, dtype, request):
pa_dtype = dtype.pyarrow_dtype
if pa.types.is_timestamp(pa_dtype) and pa_dtype.tz is not None:
request.node.add_marker(
pytest.mark.xfail(
raises=NotImplementedError,
reason=f"pyarrow.type_for_alias cannot infer {pa_dtype}",
)
)
super().test_is_dtype_from_name(dtype)
def test_construct_from_string(self, dtype, request):
pa_dtype = dtype.pyarrow_dtype
if pa.types.is_timestamp(pa_dtype) and pa_dtype.tz is not None:
request.node.add_marker(
pytest.mark.xfail(
raises=NotImplementedError,
reason=f"pyarrow.type_for_alias cannot infer {pa_dtype}",
)
)
super().test_construct_from_string(dtype)
def test_construct_from_string_another_type_raises(self, dtype):
msg = r"'another_type' must end with '\[pyarrow\]'"
with pytest.raises(TypeError, match=msg):
type(dtype).construct_from_string("another_type")
def test_get_common_dtype(self, dtype, request):
pa_dtype = dtype.pyarrow_dtype
if (
pa.types.is_date(pa_dtype)
or pa.types.is_time(pa_dtype)
or (
pa.types.is_timestamp(pa_dtype)
and (pa_dtype.unit != "ns" or pa_dtype.tz is not None)
)
or (pa.types.is_duration(pa_dtype) and pa_dtype.unit != "ns")
):
request.node.add_marker(
pytest.mark.xfail(
reason=(
f"{pa_dtype} does not have associated numpy "
f"dtype findable by find_common_type"
)
)
)
super().test_get_common_dtype(dtype)
class TestBaseIndex(base.BaseIndexTests):
pass
class TestBaseInterface(base.BaseInterfaceTests):
def test_contains(self, data, data_missing, request):
tz = getattr(data.dtype.pyarrow_dtype, "tz", None)
unit = getattr(data.dtype.pyarrow_dtype, "unit", None)
if pa_version_under2p0 and tz not in (None, "UTC") and unit == "us":
request.node.add_marker(
pytest.mark.xfail(
reason=(
f"Not supported by pyarrow < 2.0 "
f"with timestamp type {tz} and {unit}"
)
)
)
super().test_contains(data, data_missing)
@pytest.mark.xfail(reason="pyarrow.ChunkedArray does not support views.")
def test_view(self, data):
super().test_view(data)
class TestBaseMissing(base.BaseMissingTests):
def test_fillna_limit_pad(self, data_missing, using_array_manager, request):
if using_array_manager and pa.types.is_duration(
data_missing.dtype.pyarrow_dtype
):
request.node.add_marker(
pytest.mark.xfail(
reason="Checking ndim when using arraymanager with duration type"
)
)
super().test_fillna_limit_pad(data_missing)
def test_fillna_limit_backfill(self, data_missing, using_array_manager, request):
if using_array_manager and pa.types.is_duration(
data_missing.dtype.pyarrow_dtype
):
request.node.add_marker(
pytest.mark.xfail(
reason="Checking ndim when using arraymanager with duration type"
)
)
super().test_fillna_limit_backfill(data_missing)
def test_fillna_series(self, data_missing, using_array_manager, request):
if using_array_manager and pa.types.is_duration(
data_missing.dtype.pyarrow_dtype
):
request.node.add_marker(
pytest.mark.xfail(
reason="Checking ndim when using arraymanager with duration type"
)
)
super().test_fillna_series(data_missing)
def test_fillna_series_method(
self, data_missing, fillna_method, using_array_manager, request
):
if using_array_manager and pa.types.is_duration(
data_missing.dtype.pyarrow_dtype
):
request.node.add_marker(
pytest.mark.xfail(
reason="Checking ndim when using arraymanager with duration type"
)
)
super().test_fillna_series_method(data_missing, fillna_method)
def test_fillna_frame(self, data_missing, using_array_manager, request):
if using_array_manager and pa.types.is_duration(
data_missing.dtype.pyarrow_dtype
):
request.node.add_marker(
pytest.mark.xfail(
reason="Checking ndim when using arraymanager with duration type"
)
)
super().test_fillna_frame(data_missing)
class TestBasePrinting(base.BasePrintingTests):
def test_series_repr(self, data, request):
pa_dtype = data.dtype.pyarrow_dtype
if (
pa.types.is_date(pa_dtype)
or pa.types.is_duration(pa_dtype)
or (pa.types.is_timestamp(pa_dtype) and pa_dtype.tz is None)
):
request.node.add_marker(
pytest.mark.xfail(
raises=TypeError,
reason="GH 47514: _concat_datetime expects axis arg.",
)
)
super().test_series_repr(data)
def test_dataframe_repr(self, data, request):
pa_dtype = data.dtype.pyarrow_dtype
if (
pa.types.is_date(pa_dtype)
or pa.types.is_duration(pa_dtype)
or (pa.types.is_timestamp(pa_dtype) and pa_dtype.tz is None)
):
request.node.add_marker(
pytest.mark.xfail(
raises=TypeError,
reason="GH 47514: _concat_datetime expects axis arg.",
)
)
super().test_dataframe_repr(data)
class TestBaseReshaping(base.BaseReshapingTests):
@pytest.mark.parametrize("in_frame", [True, False])
def test_concat(self, data, in_frame, request):
pa_dtype = data.dtype.pyarrow_dtype
if (
pa.types.is_date(pa_dtype)
or pa.types.is_duration(pa_dtype)
or (pa.types.is_timestamp(pa_dtype) and pa_dtype.tz is None)
):
request.node.add_marker(
pytest.mark.xfail(
raises=TypeError,
reason="GH 47514: _concat_datetime expects axis arg.",
)
)
super().test_concat(data, in_frame)
@pytest.mark.parametrize("in_frame", [True, False])
def test_concat_all_na_block(self, data_missing, in_frame, request):
pa_dtype = data_missing.dtype.pyarrow_dtype
if (
pa.types.is_date(pa_dtype)
or pa.types.is_duration(pa_dtype)
or (pa.types.is_timestamp(pa_dtype) and pa_dtype.tz is None)
):
request.node.add_marker(
pytest.mark.xfail(
raises=TypeError,
reason="GH 47514: _concat_datetime expects axis arg.",
)
)
super().test_concat_all_na_block(data_missing, in_frame)
def test_concat_columns(self, data, na_value, request):
tz = getattr(data.dtype.pyarrow_dtype, "tz", None)
if pa_version_under2p0 and tz not in (None, "UTC"):
request.node.add_marker(
pytest.mark.xfail(
reason=f"Not supported by pyarrow < 2.0 with timestamp type {tz}"
)
)
super().test_concat_columns(data, na_value)
def test_concat_extension_arrays_copy_false(self, data, na_value, request):
tz = getattr(data.dtype.pyarrow_dtype, "tz", None)
if pa_version_under2p0 and tz not in (None, "UTC"):
request.node.add_marker(
pytest.mark.xfail(
reason=f"Not supported by pyarrow < 2.0 with timestamp type {tz}"
)
)
super().test_concat_extension_arrays_copy_false(data, na_value)
def test_concat_with_reindex(self, data, request, using_array_manager):
pa_dtype = data.dtype.pyarrow_dtype
if pa.types.is_duration(pa_dtype):
request.node.add_marker(
pytest.mark.xfail(
raises=TypeError,
reason="GH 47514: _concat_datetime expects axis arg.",
)
)
elif pa.types.is_date(pa_dtype) or (
pa.types.is_timestamp(pa_dtype) and pa_dtype.tz is None
):
request.node.add_marker(
pytest.mark.xfail(
raises=AttributeError if not using_array_manager else TypeError,
reason="GH 34986",
)
)
super().test_concat_with_reindex(data)
def test_align(self, data, na_value, request):
tz = getattr(data.dtype.pyarrow_dtype, "tz", None)
if pa_version_under2p0 and tz not in (None, "UTC"):
request.node.add_marker(
pytest.mark.xfail(
reason=f"Not supported by pyarrow < 2.0 with timestamp type {tz}"
)
)
super().test_align(data, na_value)
def test_align_frame(self, data, na_value, request):
tz = getattr(data.dtype.pyarrow_dtype, "tz", None)
if pa_version_under2p0 and tz not in (None, "UTC"):
request.node.add_marker(
pytest.mark.xfail(
reason=f"Not supported by pyarrow < 2.0 with timestamp type {tz}"
)
)
super().test_align_frame(data, na_value)
def test_align_series_frame(self, data, na_value, request):
tz = getattr(data.dtype.pyarrow_dtype, "tz", None)
if pa_version_under2p0 and tz not in (None, "UTC"):
request.node.add_marker(
pytest.mark.xfail(
reason=f"Not supported by pyarrow < 2.0 with timestamp type {tz}"
)
)
super().test_align_series_frame(data, na_value)
def test_merge(self, data, na_value, request):
tz = getattr(data.dtype.pyarrow_dtype, "tz", None)
if pa_version_under2p0 and tz not in (None, "UTC"):
request.node.add_marker(
pytest.mark.xfail(
reason=f"Not supported by pyarrow < 2.0 with timestamp type {tz}"
)
)
super().test_merge(data, na_value)
def test_merge_on_extension_array(self, data, request):
pa_dtype = data.dtype.pyarrow_dtype
if pa.types.is_date(pa_dtype) or (
pa.types.is_timestamp(pa_dtype) and pa_dtype.tz is None
):
request.node.add_marker(
pytest.mark.xfail(
raises=AttributeError,
reason="GH 34986",
)
)
super().test_merge_on_extension_array(data)
def test_merge_on_extension_array_duplicates(self, data, request):
pa_dtype = data.dtype.pyarrow_dtype
if pa.types.is_date(pa_dtype) or (
pa.types.is_timestamp(pa_dtype) and pa_dtype.tz is None
):
request.node.add_marker(
pytest.mark.xfail(
raises=AttributeError,
reason="GH 34986",
)
)
super().test_merge_on_extension_array_duplicates(data)
def test_ravel(self, data, request):
tz = getattr(data.dtype.pyarrow_dtype, "tz", None)
if pa_version_under2p0 and tz not in (None, "UTC"):
request.node.add_marker(
pytest.mark.xfail(
reason=f"Not supported by pyarrow < 2.0 with timestamp type {tz}"
)
)
super().test_ravel(data)
@pytest.mark.xfail(reason="GH 45419: pyarrow.ChunkedArray does not support views")
def test_transpose(self, data):
super().test_transpose(data)
def test_transpose_frame(self, data, request):
tz = getattr(data.dtype.pyarrow_dtype, "tz", None)
if pa_version_under2p0 and tz not in (None, "UTC"):
request.node.add_marker(
pytest.mark.xfail(
reason=f"Not supported by pyarrow < 2.0 with timestamp type {tz}"
)
)
super().test_transpose_frame(data)
class TestBaseSetitem(base.BaseSetitemTests):
def test_setitem_scalar_series(self, data, box_in_series, request):
tz = getattr(data.dtype.pyarrow_dtype, "tz", None)
if pa_version_under2p0 and tz not in (None, "UTC"):
request.node.add_marker(
pytest.mark.xfail(
reason=f"Not supported by pyarrow < 2.0 with timestamp type {tz}"
)
)
super().test_setitem_scalar_series(data, box_in_series)
def test_setitem_sequence(self, data, box_in_series, using_array_manager, request):
tz = getattr(data.dtype.pyarrow_dtype, "tz", None)
if pa_version_under2p0 and tz not in (None, "UTC"):
request.node.add_marker(
pytest.mark.xfail(
reason=(f"Not supported by pyarrow < 2.0 with timestamp type {tz}")
)
)
elif (
using_array_manager
and pa.types.is_duration(data.dtype.pyarrow_dtype)
and box_in_series
):
request.node.add_marker(
pytest.mark.xfail(
reason="Checking ndim when using arraymanager with duration type"
)
)
super().test_setitem_sequence(data, box_in_series)
def test_setitem_sequence_mismatched_length_raises(
self, data, as_array, using_array_manager, request
):
if using_array_manager and pa.types.is_duration(data.dtype.pyarrow_dtype):
request.node.add_marker(
pytest.mark.xfail(
reason="Checking ndim when using arraymanager with duration type"
)
)
super().test_setitem_sequence_mismatched_length_raises(data, as_array)
def test_setitem_empty_indexer(
self, data, box_in_series, using_array_manager, request
):
if (
using_array_manager
and pa.types.is_duration(data.dtype.pyarrow_dtype)
and box_in_series
):
request.node.add_marker(
pytest.mark.xfail(
reason="Checking ndim when using arraymanager with duration type"
)
)
super().test_setitem_empty_indexer(data, box_in_series)
def test_setitem_sequence_broadcasts(
self, data, box_in_series, using_array_manager, request
):
tz = getattr(data.dtype.pyarrow_dtype, "tz", None)
if pa_version_under2p0 and tz not in (None, "UTC"):
request.node.add_marker(
pytest.mark.xfail(
reason=(f"Not supported by pyarrow < 2.0 with timestamp type {tz}")
)
)
elif (
using_array_manager
and pa.types.is_duration(data.dtype.pyarrow_dtype)
and box_in_series
):
request.node.add_marker(
pytest.mark.xfail(
reason="Checking ndim when using arraymanager with duration type"
)
)
super().test_setitem_sequence_broadcasts(data, box_in_series)
@pytest.mark.parametrize("setter", ["loc", "iloc"])
def test_setitem_scalar(self, data, setter, using_array_manager, request):
tz = getattr(data.dtype.pyarrow_dtype, "tz", None)
if pa_version_under2p0 and tz not in (None, "UTC"):
request.node.add_marker(
pytest.mark.xfail(
reason=(f"Not supported by pyarrow < 2.0 with timestamp type {tz}")
)
)
elif using_array_manager and pa.types.is_duration(data.dtype.pyarrow_dtype):
request.node.add_marker(
pytest.mark.xfail(
reason="Checking ndim when using arraymanager with duration type"
)
)
super().test_setitem_scalar(data, setter)
def test_setitem_loc_scalar_mixed(self, data, using_array_manager, request):
tz = getattr(data.dtype.pyarrow_dtype, "tz", None)
if pa_version_under2p0 and tz not in (None, "UTC"):
request.node.add_marker(
pytest.mark.xfail(
reason=(f"Not supported by pyarrow < 2.0 with timestamp type {tz}")
)
)
elif using_array_manager and pa.types.is_duration(data.dtype.pyarrow_dtype):
request.node.add_marker(
pytest.mark.xfail(
reason="Checking ndim when using arraymanager with duration type"
)
)
super().test_setitem_loc_scalar_mixed(data)
def test_setitem_loc_scalar_single(self, data, using_array_manager, request):
tz = getattr(data.dtype.pyarrow_dtype, "tz", None)
if pa_version_under2p0 and tz not in (None, "UTC"):
request.node.add_marker(
pytest.mark.xfail(
reason=f"Not supported by pyarrow < 2.0 with timestamp type {tz}"
)
)
elif using_array_manager and pa.types.is_duration(data.dtype.pyarrow_dtype):
request.node.add_marker(
pytest.mark.xfail(
reason="Checking ndim when using arraymanager with duration type"
)
)
super().test_setitem_loc_scalar_single(data)
def test_setitem_loc_scalar_multiple_homogoneous(
self, data, using_array_manager, request
):
tz = getattr(data.dtype.pyarrow_dtype, "tz", None)
if pa_version_under2p0 and tz not in (None, "UTC"):
request.node.add_marker(
pytest.mark.xfail(
reason=(f"Not supported by pyarrow < 2.0 with timestamp type {tz}")
)
)
elif using_array_manager and pa.types.is_duration(data.dtype.pyarrow_dtype):
request.node.add_marker(
pytest.mark.xfail(
reason="Checking ndim when using arraymanager with duration type"
)
)
super().test_setitem_loc_scalar_multiple_homogoneous(data)
def test_setitem_iloc_scalar_mixed(self, data, using_array_manager, request):
tz = getattr(data.dtype.pyarrow_dtype, "tz", None)
if pa_version_under2p0 and tz not in (None, "UTC"):
request.node.add_marker(
pytest.mark.xfail(
reason=(f"Not supported by pyarrow < 2.0 with timestamp type {tz}")
)
)
elif using_array_manager and pa.types.is_duration(data.dtype.pyarrow_dtype):
request.node.add_marker(
pytest.mark.xfail(
reason="Checking ndim when using arraymanager with duration type"
)
)
super().test_setitem_iloc_scalar_mixed(data)
def test_setitem_iloc_scalar_single(self, data, using_array_manager, request):
tz = getattr(data.dtype.pyarrow_dtype, "tz", None)
if pa_version_under2p0 and tz not in (None, "UTC"):
request.node.add_marker(
pytest.mark.xfail(
reason=(f"Not supported by pyarrow < 2.0 with timestamp type {tz}")
)
)
elif using_array_manager and pa.types.is_duration(data.dtype.pyarrow_dtype):
request.node.add_marker(
pytest.mark.xfail(
reason="Checking ndim when using arraymanager with duration type"
)
)
super().test_setitem_iloc_scalar_single(data)
def test_setitem_iloc_scalar_multiple_homogoneous(
self, data, using_array_manager, request
):
tz = getattr(data.dtype.pyarrow_dtype, "tz", None)
if pa_version_under2p0 and tz not in (None, "UTC"):
request.node.add_marker(
pytest.mark.xfail(
reason=(f"Not supported by pyarrow < 2.0 with timestamp type {tz}")
)
)
elif using_array_manager and pa.types.is_duration(data.dtype.pyarrow_dtype):
request.node.add_marker(
pytest.mark.xfail(
reason="Checking ndim when using arraymanager with duration type"
)
)
super().test_setitem_iloc_scalar_multiple_homogoneous(data)
@pytest.mark.parametrize(
"mask",
[
np.array([True, True, True, False, False]),
pd.array([True, True, True, False, False], dtype="boolean"),
pd.array([True, True, True, pd.NA, pd.NA], dtype="boolean"),
],
ids=["numpy-array", "boolean-array", "boolean-array-na"],
)
def test_setitem_mask(
self, data, mask, box_in_series, using_array_manager, request
):
tz = getattr(data.dtype.pyarrow_dtype, "tz", None)
if pa_version_under2p0 and tz not in (None, "UTC"):
request.node.add_marker(
pytest.mark.xfail(
reason=(f"Not supported by pyarrow < 2.0 with timestamp type {tz}")
)
)
elif (
using_array_manager
and pa.types.is_duration(data.dtype.pyarrow_dtype)
and box_in_series
):
request.node.add_marker(
pytest.mark.xfail(
reason="Checking ndim when using arraymanager with duration type"
)
)
super().test_setitem_mask(data, mask, box_in_series)