Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wiseplat
GitHub Repository: wiseplat/python-code
Path: blob/master/ invest-robot-contest_TinkoffBotTwitch-main/venv/lib/python3.8/site-packages/pandas/conftest.py
7799 views
1
"""
2
This file is very long and growing, but it was decided to not split it yet, as
3
it's still manageable (2020-03-17, ~1.1k LoC). See gh-31989
4
5
Instead of splitting it was decided to define sections here:
6
- Configuration / Settings
7
- Autouse fixtures
8
- Common arguments
9
- Missing values & co.
10
- Classes
11
- Indices
12
- Series'
13
- DataFrames
14
- Operators & Operations
15
- Data sets/files
16
- Time zones
17
- Dtypes
18
- Misc
19
"""
20
# pyright: reportUntypedFunctionDecorator = false
21
22
from collections import abc
23
from datetime import (
24
date,
25
datetime,
26
time,
27
timedelta,
28
timezone,
29
)
30
from decimal import Decimal
31
import operator
32
import os
33
34
from dateutil.tz import (
35
tzlocal,
36
tzutc,
37
)
38
import hypothesis
39
from hypothesis import strategies as st
40
import numpy as np
41
import pytest
42
from pytz import (
43
FixedOffset,
44
utc,
45
)
46
47
import pandas.util._test_decorators as td
48
49
from pandas.core.dtypes.dtypes import (
50
DatetimeTZDtype,
51
IntervalDtype,
52
)
53
54
import pandas as pd
55
from pandas import (
56
DataFrame,
57
Interval,
58
Period,
59
Series,
60
Timedelta,
61
Timestamp,
62
)
63
import pandas._testing as tm
64
from pandas.core import ops
65
from pandas.core.indexes.api import (
66
Index,
67
MultiIndex,
68
)
69
70
try:
71
import pyarrow as pa
72
except ImportError:
73
has_pyarrow = False
74
else:
75
del pa
76
has_pyarrow = True
77
78
# Until https://github.com/numpy/numpy/issues/19078 is sorted out, just suppress
79
suppress_npdev_promotion_warning = pytest.mark.filterwarnings(
80
"ignore:Promotion of numbers and bools:FutureWarning"
81
)
82
83
# ----------------------------------------------------------------
84
# Configuration / Settings
85
# ----------------------------------------------------------------
86
# pytest
87
88
89
def pytest_addoption(parser):
90
parser.addoption("--skip-slow", action="store_true", help="skip slow tests")
91
parser.addoption("--skip-network", action="store_true", help="skip network tests")
92
parser.addoption("--skip-db", action="store_true", help="skip db tests")
93
parser.addoption(
94
"--run-high-memory", action="store_true", help="run high memory tests"
95
)
96
parser.addoption("--only-slow", action="store_true", help="run only slow tests")
97
parser.addoption(
98
"--strict-data-files",
99
action="store_true",
100
help="Fail if a test is skipped for missing data file.",
101
)
102
103
104
def pytest_collection_modifyitems(items, config):
105
skip_slow = config.getoption("--skip-slow")
106
only_slow = config.getoption("--only-slow")
107
skip_network = config.getoption("--skip-network")
108
skip_db = config.getoption("--skip-db")
109
run_high_memory = config.getoption("--run-high-memory")
110
111
marks = [
112
(pytest.mark.slow, "slow", skip_slow, "--skip-slow"),
113
(pytest.mark.network, "network", skip_network, "--network"),
114
(pytest.mark.db, "db", skip_db, "--skip-db"),
115
]
116
117
for item in items:
118
if config.getoption("--doctest-modules") or config.getoption(
119
"--doctest-cython", default=False
120
):
121
# autouse=True for the add_doctest_imports can lead to expensive teardowns
122
# since doctest_namespace is a session fixture
123
item.add_marker(pytest.mark.usefixtures("add_doctest_imports"))
124
# mark all tests in the pandas/tests/frame directory with "arraymanager"
125
if "/frame/" in item.nodeid:
126
item.add_marker(pytest.mark.arraymanager)
127
item.add_marker(suppress_npdev_promotion_warning)
128
129
for (mark, kwd, skip_if_found, arg_name) in marks:
130
if kwd in item.keywords:
131
# If we're skipping, no need to actually add the marker or look for
132
# other markers
133
if skip_if_found:
134
item.add_marker(pytest.mark.skip(f"skipping due to {arg_name}"))
135
break
136
137
item.add_marker(mark)
138
139
if only_slow and "slow" not in item.keywords:
140
item.add_marker(pytest.mark.skip("skipping due to --only-slow"))
141
142
if "high_memory" in item.keywords and not run_high_memory:
143
item.add_marker(
144
pytest.mark.skip(
145
"skipping high memory test since --run-high-memory was not set"
146
)
147
)
148
149
150
# Hypothesis
151
hypothesis.settings.register_profile(
152
"ci",
153
# Hypothesis timing checks are tuned for scalars by default, so we bump
154
# them from 200ms to 500ms per test case as the global default. If this
155
# is too short for a specific test, (a) try to make it faster, and (b)
156
# if it really is slow add `@settings(deadline=...)` with a working value,
157
# or `deadline=None` to entirely disable timeouts for that test.
158
# 2022-02-09: Changed deadline from 500 -> None. Deadline leads to
159
# non-actionable, flaky CI failures (# GH 24641, 44969, 45118, 44969)
160
deadline=None,
161
suppress_health_check=(hypothesis.HealthCheck.too_slow,),
162
)
163
hypothesis.settings.load_profile("ci")
164
165
# Registering these strategies makes them globally available via st.from_type,
166
# which is use for offsets in tests/tseries/offsets/test_offsets_properties.py
167
for name in "MonthBegin MonthEnd BMonthBegin BMonthEnd".split():
168
cls = getattr(pd.tseries.offsets, name)
169
st.register_type_strategy(
170
cls, st.builds(cls, n=st.integers(-99, 99), normalize=st.booleans())
171
)
172
173
for name in "YearBegin YearEnd BYearBegin BYearEnd".split():
174
cls = getattr(pd.tseries.offsets, name)
175
st.register_type_strategy(
176
cls,
177
st.builds(
178
cls,
179
n=st.integers(-5, 5),
180
normalize=st.booleans(),
181
month=st.integers(min_value=1, max_value=12),
182
),
183
)
184
185
for name in "QuarterBegin QuarterEnd BQuarterBegin BQuarterEnd".split():
186
cls = getattr(pd.tseries.offsets, name)
187
st.register_type_strategy(
188
cls,
189
st.builds(
190
cls,
191
n=st.integers(-24, 24),
192
normalize=st.booleans(),
193
startingMonth=st.integers(min_value=1, max_value=12),
194
),
195
)
196
197
198
@pytest.fixture
199
def add_doctest_imports(doctest_namespace):
200
"""
201
Make `np` and `pd` names available for doctests.
202
"""
203
doctest_namespace["np"] = np
204
doctest_namespace["pd"] = pd
205
206
207
# ----------------------------------------------------------------
208
# Autouse fixtures
209
# ----------------------------------------------------------------
210
@pytest.fixture(autouse=True)
211
def configure_tests():
212
"""
213
Configure settings for all tests and test modules.
214
"""
215
pd.set_option("chained_assignment", "raise")
216
217
218
# ----------------------------------------------------------------
219
# Common arguments
220
# ----------------------------------------------------------------
221
@pytest.fixture(params=[0, 1, "index", "columns"], ids=lambda x: f"axis={repr(x)}")
222
def axis(request):
223
"""
224
Fixture for returning the axis numbers of a DataFrame.
225
"""
226
return request.param
227
228
229
axis_frame = axis
230
231
232
@pytest.fixture(params=[True, False, None])
233
def observed(request):
234
"""
235
Pass in the observed keyword to groupby for [True, False]
236
This indicates whether categoricals should return values for
237
values which are not in the grouper [False / None], or only values which
238
appear in the grouper [True]. [None] is supported for future compatibility
239
if we decide to change the default (and would need to warn if this
240
parameter is not passed).
241
"""
242
return request.param
243
244
245
@pytest.fixture(params=[True, False, None])
246
def ordered(request):
247
"""
248
Boolean 'ordered' parameter for Categorical.
249
"""
250
return request.param
251
252
253
@pytest.fixture(params=["first", "last", False])
254
def keep(request):
255
"""
256
Valid values for the 'keep' parameter used in
257
.duplicated or .drop_duplicates
258
"""
259
return request.param
260
261
262
@pytest.fixture(params=["both", "neither", "left", "right"])
263
def inclusive_endpoints_fixture(request):
264
"""
265
Fixture for trying all interval 'inclusive' parameters.
266
"""
267
return request.param
268
269
270
@pytest.fixture(params=["left", "right", "both", "neither"])
271
def closed(request):
272
"""
273
Fixture for trying all interval closed parameters.
274
"""
275
return request.param
276
277
278
@pytest.fixture(params=["left", "right", "both", "neither"])
279
def other_closed(request):
280
"""
281
Secondary closed fixture to allow parametrizing over all pairs of closed.
282
"""
283
return request.param
284
285
286
@pytest.fixture(
287
params=[
288
None,
289
"gzip",
290
"bz2",
291
"zip",
292
"xz",
293
pytest.param("zstd", marks=td.skip_if_no("zstandard")),
294
]
295
)
296
def compression(request):
297
"""
298
Fixture for trying common compression types in compression tests.
299
"""
300
return request.param
301
302
303
@pytest.fixture(
304
params=[
305
"gzip",
306
"bz2",
307
"zip",
308
"xz",
309
pytest.param("zstd", marks=td.skip_if_no("zstandard")),
310
]
311
)
312
def compression_only(request):
313
"""
314
Fixture for trying common compression types in compression tests excluding
315
uncompressed case.
316
"""
317
return request.param
318
319
320
@pytest.fixture(params=[True, False])
321
def writable(request):
322
"""
323
Fixture that an array is writable.
324
"""
325
return request.param
326
327
328
@pytest.fixture(params=["inner", "outer", "left", "right"])
329
def join_type(request):
330
"""
331
Fixture for trying all types of join operations.
332
"""
333
return request.param
334
335
336
@pytest.fixture(params=["nlargest", "nsmallest"])
337
def nselect_method(request):
338
"""
339
Fixture for trying all nselect methods.
340
"""
341
return request.param
342
343
344
# ----------------------------------------------------------------
345
# Missing values & co.
346
# ----------------------------------------------------------------
347
@pytest.fixture(params=tm.NULL_OBJECTS, ids=lambda x: type(x).__name__)
348
def nulls_fixture(request):
349
"""
350
Fixture for each null type in pandas.
351
"""
352
return request.param
353
354
355
nulls_fixture2 = nulls_fixture # Generate cartesian product of nulls_fixture
356
357
358
@pytest.fixture(params=[None, np.nan, pd.NaT])
359
def unique_nulls_fixture(request):
360
"""
361
Fixture for each null type in pandas, each null type exactly once.
362
"""
363
return request.param
364
365
366
# Generate cartesian product of unique_nulls_fixture:
367
unique_nulls_fixture2 = unique_nulls_fixture
368
369
370
@pytest.fixture(params=tm.NP_NAT_OBJECTS, ids=lambda x: type(x).__name__)
371
def np_nat_fixture(request):
372
"""
373
Fixture for each NaT type in numpy.
374
"""
375
return request.param
376
377
378
# Generate cartesian product of np_nat_fixture:
379
np_nat_fixture2 = np_nat_fixture
380
381
382
# ----------------------------------------------------------------
383
# Classes
384
# ----------------------------------------------------------------
385
386
387
@pytest.fixture(params=[DataFrame, Series])
388
def frame_or_series(request):
389
"""
390
Fixture to parametrize over DataFrame and Series.
391
"""
392
return request.param
393
394
395
# error: List item 0 has incompatible type "Type[Index]"; expected "Type[IndexOpsMixin]"
396
@pytest.fixture(
397
params=[Index, Series], ids=["index", "series"] # type: ignore[list-item]
398
)
399
def index_or_series(request):
400
"""
401
Fixture to parametrize over Index and Series, made necessary by a mypy
402
bug, giving an error:
403
404
List item 0 has incompatible type "Type[Series]"; expected "Type[PandasObject]"
405
406
See GH#29725
407
"""
408
return request.param
409
410
411
# Generate cartesian product of index_or_series fixture:
412
index_or_series2 = index_or_series
413
414
415
@pytest.fixture(params=[Index, Series, pd.array], ids=["index", "series", "array"])
416
def index_or_series_or_array(request):
417
"""
418
Fixture to parametrize over Index, Series, and ExtensionArray
419
"""
420
return request.param
421
422
423
@pytest.fixture(params=[Index, Series, DataFrame, pd.array], ids=lambda x: x.__name__)
424
def box_with_array(request):
425
"""
426
Fixture to test behavior for Index, Series, DataFrame, and pandas Array
427
classes
428
"""
429
return request.param
430
431
432
box_with_array2 = box_with_array
433
434
435
@pytest.fixture
436
def dict_subclass():
437
"""
438
Fixture for a dictionary subclass.
439
"""
440
441
class TestSubDict(dict):
442
def __init__(self, *args, **kwargs):
443
dict.__init__(self, *args, **kwargs)
444
445
return TestSubDict
446
447
448
@pytest.fixture
449
def non_dict_mapping_subclass():
450
"""
451
Fixture for a non-mapping dictionary subclass.
452
"""
453
454
class TestNonDictMapping(abc.Mapping):
455
def __init__(self, underlying_dict):
456
self._data = underlying_dict
457
458
def __getitem__(self, key):
459
return self._data.__getitem__(key)
460
461
def __iter__(self):
462
return self._data.__iter__()
463
464
def __len__(self):
465
return self._data.__len__()
466
467
return TestNonDictMapping
468
469
470
# ----------------------------------------------------------------
471
# Indices
472
# ----------------------------------------------------------------
473
@pytest.fixture
474
def multiindex_year_month_day_dataframe_random_data():
475
"""
476
DataFrame with 3 level MultiIndex (year, month, day) covering
477
first 100 business days from 2000-01-01 with random data
478
"""
479
tdf = tm.makeTimeDataFrame(100)
480
ymd = tdf.groupby([lambda x: x.year, lambda x: x.month, lambda x: x.day]).sum()
481
# use Int64Index, to make sure things work
482
ymd.index = ymd.index.set_levels([lev.astype("i8") for lev in ymd.index.levels])
483
ymd.index.set_names(["year", "month", "day"], inplace=True)
484
return ymd
485
486
487
@pytest.fixture
488
def lexsorted_two_level_string_multiindex():
489
"""
490
2-level MultiIndex, lexsorted, with string names.
491
"""
492
return MultiIndex(
493
levels=[["foo", "bar", "baz", "qux"], ["one", "two", "three"]],
494
codes=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3], [0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],
495
names=["first", "second"],
496
)
497
498
499
@pytest.fixture
500
def multiindex_dataframe_random_data(lexsorted_two_level_string_multiindex):
501
"""DataFrame with 2 level MultiIndex with random data"""
502
index = lexsorted_two_level_string_multiindex
503
return DataFrame(
504
np.random.randn(10, 3), index=index, columns=Index(["A", "B", "C"], name="exp")
505
)
506
507
508
def _create_multiindex():
509
"""
510
MultiIndex used to test the general functionality of this object
511
"""
512
513
# See Also: tests.multi.conftest.idx
514
major_axis = Index(["foo", "bar", "baz", "qux"])
515
minor_axis = Index(["one", "two"])
516
517
major_codes = np.array([0, 0, 1, 2, 3, 3])
518
minor_codes = np.array([0, 1, 0, 1, 0, 1])
519
index_names = ["first", "second"]
520
return MultiIndex(
521
levels=[major_axis, minor_axis],
522
codes=[major_codes, minor_codes],
523
names=index_names,
524
verify_integrity=False,
525
)
526
527
528
def _create_mi_with_dt64tz_level():
529
"""
530
MultiIndex with a level that is a tzaware DatetimeIndex.
531
"""
532
# GH#8367 round trip with pickle
533
return MultiIndex.from_product(
534
[[1, 2], ["a", "b"], pd.date_range("20130101", periods=3, tz="US/Eastern")],
535
names=["one", "two", "three"],
536
)
537
538
539
indices_dict = {
540
"unicode": tm.makeUnicodeIndex(100),
541
"string": tm.makeStringIndex(100),
542
"datetime": tm.makeDateIndex(100),
543
"datetime-tz": tm.makeDateIndex(100, tz="US/Pacific"),
544
"period": tm.makePeriodIndex(100),
545
"timedelta": tm.makeTimedeltaIndex(100),
546
"int": tm.makeIntIndex(100),
547
"uint": tm.makeUIntIndex(100),
548
"range": tm.makeRangeIndex(100),
549
"float": tm.makeFloatIndex(100),
550
"num_int64": tm.makeNumericIndex(100, dtype="int64"),
551
"num_int32": tm.makeNumericIndex(100, dtype="int32"),
552
"num_int16": tm.makeNumericIndex(100, dtype="int16"),
553
"num_int8": tm.makeNumericIndex(100, dtype="int8"),
554
"num_uint64": tm.makeNumericIndex(100, dtype="uint64"),
555
"num_uint32": tm.makeNumericIndex(100, dtype="uint32"),
556
"num_uint16": tm.makeNumericIndex(100, dtype="uint16"),
557
"num_uint8": tm.makeNumericIndex(100, dtype="uint8"),
558
"num_float64": tm.makeNumericIndex(100, dtype="float64"),
559
"num_float32": tm.makeNumericIndex(100, dtype="float32"),
560
"bool": tm.makeBoolIndex(10),
561
"categorical": tm.makeCategoricalIndex(100),
562
"interval": tm.makeIntervalIndex(100),
563
"empty": Index([]),
564
"tuples": MultiIndex.from_tuples(zip(["foo", "bar", "baz"], [1, 2, 3])),
565
"mi-with-dt64tz-level": _create_mi_with_dt64tz_level(),
566
"multi": _create_multiindex(),
567
"repeats": Index([0, 0, 1, 1, 2, 2]),
568
"nullable_int": Index(np.arange(100), dtype="Int64"),
569
"nullable_uint": Index(np.arange(100), dtype="UInt16"),
570
"nullable_float": Index(np.arange(100), dtype="Float32"),
571
"nullable_bool": Index(np.arange(100).astype(bool), dtype="boolean"),
572
"string-python": Index(pd.array(tm.makeStringIndex(100), dtype="string[python]")),
573
}
574
if has_pyarrow:
575
idx = Index(pd.array(tm.makeStringIndex(100), dtype="string[pyarrow]"))
576
indices_dict["string-pyarrow"] = idx
577
578
579
@pytest.fixture(params=indices_dict.keys())
580
def index(request):
581
"""
582
Fixture for many "simple" kinds of indices.
583
584
These indices are unlikely to cover corner cases, e.g.
585
- no names
586
- no NaTs/NaNs
587
- no values near implementation bounds
588
- ...
589
"""
590
# copy to avoid mutation, e.g. setting .name
591
return indices_dict[request.param].copy()
592
593
594
# Needed to generate cartesian product of indices
595
index_fixture2 = index
596
597
598
@pytest.fixture(
599
params=[
600
key for key in indices_dict if not isinstance(indices_dict[key], MultiIndex)
601
]
602
)
603
def index_flat(request):
604
"""
605
index fixture, but excluding MultiIndex cases.
606
"""
607
key = request.param
608
return indices_dict[key].copy()
609
610
611
# Alias so we can test with cartesian product of index_flat
612
index_flat2 = index_flat
613
614
615
@pytest.fixture(
616
params=[
617
key
618
for key in indices_dict
619
if not isinstance(indices_dict[key], MultiIndex) and indices_dict[key].is_unique
620
]
621
)
622
def index_flat_unique(request):
623
"""
624
index_flat with uniqueness requirement.
625
"""
626
key = request.param
627
return indices_dict[key].copy()
628
629
630
@pytest.fixture(
631
params=[
632
key
633
for key in indices_dict
634
if not (
635
key in ["int", "uint", "range", "empty", "repeats"]
636
or key.startswith("num_")
637
)
638
and not isinstance(indices_dict[key], MultiIndex)
639
]
640
)
641
def index_with_missing(request):
642
"""
643
Fixture for indices with missing values.
644
645
Integer-dtype and empty cases are excluded because they cannot hold missing
646
values.
647
648
MultiIndex is excluded because isna() is not defined for MultiIndex.
649
"""
650
651
# GH 35538. Use deep copy to avoid illusive bug on np-dev
652
# Azure pipeline that writes into indices_dict despite copy
653
ind = indices_dict[request.param].copy(deep=True)
654
vals = ind.values
655
if request.param in ["tuples", "mi-with-dt64tz-level", "multi"]:
656
# For setting missing values in the top level of MultiIndex
657
vals = ind.tolist()
658
vals[0] = (None,) + vals[0][1:]
659
vals[-1] = (None,) + vals[-1][1:]
660
return MultiIndex.from_tuples(vals)
661
else:
662
vals[0] = None
663
vals[-1] = None
664
return type(ind)(vals)
665
666
667
# ----------------------------------------------------------------
668
# Series'
669
# ----------------------------------------------------------------
670
@pytest.fixture
671
def string_series():
672
"""
673
Fixture for Series of floats with Index of unique strings
674
"""
675
s = tm.makeStringSeries()
676
s.name = "series"
677
return s
678
679
680
@pytest.fixture
681
def object_series():
682
"""
683
Fixture for Series of dtype object with Index of unique strings
684
"""
685
s = tm.makeObjectSeries()
686
s.name = "objects"
687
return s
688
689
690
@pytest.fixture
691
def datetime_series():
692
"""
693
Fixture for Series of floats with DatetimeIndex
694
"""
695
s = tm.makeTimeSeries()
696
s.name = "ts"
697
return s
698
699
700
def _create_series(index):
701
"""Helper for the _series dict"""
702
size = len(index)
703
data = np.random.randn(size)
704
return Series(data, index=index, name="a")
705
706
707
_series = {
708
f"series-with-{index_id}-index": _create_series(index)
709
for index_id, index in indices_dict.items()
710
}
711
712
713
@pytest.fixture
714
def series_with_simple_index(index):
715
"""
716
Fixture for tests on series with changing types of indices.
717
"""
718
return _create_series(index)
719
720
721
@pytest.fixture
722
def series_with_multilevel_index():
723
"""
724
Fixture with a Series with a 2-level MultiIndex.
725
"""
726
arrays = [
727
["bar", "bar", "baz", "baz", "qux", "qux", "foo", "foo"],
728
["one", "two", "one", "two", "one", "two", "one", "two"],
729
]
730
tuples = zip(*arrays)
731
index = MultiIndex.from_tuples(tuples)
732
data = np.random.randn(8)
733
ser = Series(data, index=index)
734
ser[3] = np.NaN
735
return ser
736
737
738
_narrow_series = {
739
f"{dtype.__name__}-series": tm.makeFloatSeries(name="a").astype(dtype)
740
for dtype in tm.NARROW_NP_DTYPES
741
}
742
743
744
_index_or_series_objs = {**indices_dict, **_series, **_narrow_series}
745
746
747
@pytest.fixture(params=_index_or_series_objs.keys())
748
def index_or_series_obj(request):
749
"""
750
Fixture for tests on indexes, series and series with a narrow dtype
751
copy to avoid mutation, e.g. setting .name
752
"""
753
return _index_or_series_objs[request.param].copy(deep=True)
754
755
756
# ----------------------------------------------------------------
757
# DataFrames
758
# ----------------------------------------------------------------
759
@pytest.fixture
760
def int_frame():
761
"""
762
Fixture for DataFrame of ints with index of unique strings
763
764
Columns are ['A', 'B', 'C', 'D']
765
766
A B C D
767
vpBeWjM651 1 0 1 0
768
5JyxmrP1En -1 0 0 0
769
qEDaoD49U2 -1 1 0 0
770
m66TkTfsFe 0 0 0 0
771
EHPaNzEUFm -1 0 -1 0
772
fpRJCevQhi 2 0 0 0
773
OlQvnmfi3Q 0 0 -2 0
774
... .. .. .. ..
775
uB1FPlz4uP 0 0 0 1
776
EcSe6yNzCU 0 0 -1 0
777
L50VudaiI8 -1 1 -2 0
778
y3bpw4nwIp 0 -1 0 0
779
H0RdLLwrCT 1 1 0 0
780
rY82K0vMwm 0 0 0 0
781
1OPIUjnkjk 2 0 0 0
782
783
[30 rows x 4 columns]
784
"""
785
return DataFrame(tm.getSeriesData()).astype("int64")
786
787
788
@pytest.fixture
789
def datetime_frame():
790
"""
791
Fixture for DataFrame of floats with DatetimeIndex
792
793
Columns are ['A', 'B', 'C', 'D']
794
795
A B C D
796
2000-01-03 -1.122153 0.468535 0.122226 1.693711
797
2000-01-04 0.189378 0.486100 0.007864 -1.216052
798
2000-01-05 0.041401 -0.835752 -0.035279 -0.414357
799
2000-01-06 0.430050 0.894352 0.090719 0.036939
800
2000-01-07 -0.620982 -0.668211 -0.706153 1.466335
801
2000-01-10 -0.752633 0.328434 -0.815325 0.699674
802
2000-01-11 -2.236969 0.615737 -0.829076 -1.196106
803
... ... ... ... ...
804
2000-02-03 1.642618 -0.579288 0.046005 1.385249
805
2000-02-04 -0.544873 -1.160962 -0.284071 -1.418351
806
2000-02-07 -2.656149 -0.601387 1.410148 0.444150
807
2000-02-08 -1.201881 -1.289040 0.772992 -1.445300
808
2000-02-09 1.377373 0.398619 1.008453 -0.928207
809
2000-02-10 0.473194 -0.636677 0.984058 0.511519
810
2000-02-11 -0.965556 0.408313 -1.312844 -0.381948
811
812
[30 rows x 4 columns]
813
"""
814
return DataFrame(tm.getTimeSeriesData())
815
816
817
@pytest.fixture
818
def float_frame():
819
"""
820
Fixture for DataFrame of floats with index of unique strings
821
822
Columns are ['A', 'B', 'C', 'D'].
823
824
A B C D
825
P7GACiRnxd -0.465578 -0.361863 0.886172 -0.053465
826
qZKh6afn8n -0.466693 -0.373773 0.266873 1.673901
827
tkp0r6Qble 0.148691 -0.059051 0.174817 1.598433
828
wP70WOCtv8 0.133045 -0.581994 -0.992240 0.261651
829
M2AeYQMnCz -1.207959 -0.185775 0.588206 0.563938
830
QEPzyGDYDo -0.381843 -0.758281 0.502575 -0.565053
831
r78Jwns6dn -0.653707 0.883127 0.682199 0.206159
832
... ... ... ... ...
833
IHEGx9NO0T -0.277360 0.113021 -1.018314 0.196316
834
lPMj8K27FA -1.313667 -0.604776 -1.305618 -0.863999
835
qa66YMWQa5 1.110525 0.475310 -0.747865 0.032121
836
yOa0ATsmcE -0.431457 0.067094 0.096567 -0.264962
837
65znX3uRNG 1.528446 0.160416 -0.109635 -0.032987
838
eCOBvKqf3e 0.235281 1.622222 0.781255 0.392871
839
xSucinXxuV -1.263557 0.252799 -0.552247 0.400426
840
841
[30 rows x 4 columns]
842
"""
843
return DataFrame(tm.getSeriesData())
844
845
846
@pytest.fixture
847
def mixed_type_frame():
848
"""
849
Fixture for DataFrame of float/int/string columns with RangeIndex
850
Columns are ['a', 'b', 'c', 'float32', 'int32'].
851
"""
852
return DataFrame(
853
{
854
"a": 1.0,
855
"b": 2,
856
"c": "foo",
857
"float32": np.array([1.0] * 10, dtype="float32"),
858
"int32": np.array([1] * 10, dtype="int32"),
859
},
860
index=np.arange(10),
861
)
862
863
864
@pytest.fixture
865
def rand_series_with_duplicate_datetimeindex():
866
"""
867
Fixture for Series with a DatetimeIndex that has duplicates.
868
"""
869
dates = [
870
datetime(2000, 1, 2),
871
datetime(2000, 1, 2),
872
datetime(2000, 1, 2),
873
datetime(2000, 1, 3),
874
datetime(2000, 1, 3),
875
datetime(2000, 1, 3),
876
datetime(2000, 1, 4),
877
datetime(2000, 1, 4),
878
datetime(2000, 1, 4),
879
datetime(2000, 1, 5),
880
]
881
882
return Series(np.random.randn(len(dates)), index=dates)
883
884
885
# ----------------------------------------------------------------
886
# Scalars
887
# ----------------------------------------------------------------
888
@pytest.fixture(
889
params=[
890
(Interval(left=0, right=5), IntervalDtype("int64", "right")),
891
(Interval(left=0.1, right=0.5), IntervalDtype("float64", "right")),
892
(Period("2012-01", freq="M"), "period[M]"),
893
(Period("2012-02-01", freq="D"), "period[D]"),
894
(
895
Timestamp("2011-01-01", tz="US/Eastern"),
896
DatetimeTZDtype(tz="US/Eastern"),
897
),
898
(Timedelta(seconds=500), "timedelta64[ns]"),
899
]
900
)
901
def ea_scalar_and_dtype(request):
902
return request.param
903
904
905
# ----------------------------------------------------------------
906
# Operators & Operations
907
# ----------------------------------------------------------------
908
_all_arithmetic_operators = [
909
"__add__",
910
"__radd__",
911
"__sub__",
912
"__rsub__",
913
"__mul__",
914
"__rmul__",
915
"__floordiv__",
916
"__rfloordiv__",
917
"__truediv__",
918
"__rtruediv__",
919
"__pow__",
920
"__rpow__",
921
"__mod__",
922
"__rmod__",
923
]
924
925
926
@pytest.fixture(params=_all_arithmetic_operators)
927
def all_arithmetic_operators(request):
928
"""
929
Fixture for dunder names for common arithmetic operations.
930
"""
931
return request.param
932
933
934
@pytest.fixture(
935
params=[
936
operator.add,
937
ops.radd,
938
operator.sub,
939
ops.rsub,
940
operator.mul,
941
ops.rmul,
942
operator.truediv,
943
ops.rtruediv,
944
operator.floordiv,
945
ops.rfloordiv,
946
operator.mod,
947
ops.rmod,
948
operator.pow,
949
ops.rpow,
950
operator.eq,
951
operator.ne,
952
operator.lt,
953
operator.le,
954
operator.gt,
955
operator.ge,
956
operator.and_,
957
ops.rand_,
958
operator.xor,
959
ops.rxor,
960
operator.or_,
961
ops.ror_,
962
]
963
)
964
def all_binary_operators(request):
965
"""
966
Fixture for operator and roperator arithmetic, comparison, and logical ops.
967
"""
968
return request.param
969
970
971
@pytest.fixture(
972
params=[
973
operator.add,
974
ops.radd,
975
operator.sub,
976
ops.rsub,
977
operator.mul,
978
ops.rmul,
979
operator.truediv,
980
ops.rtruediv,
981
operator.floordiv,
982
ops.rfloordiv,
983
operator.mod,
984
ops.rmod,
985
operator.pow,
986
ops.rpow,
987
]
988
)
989
def all_arithmetic_functions(request):
990
"""
991
Fixture for operator and roperator arithmetic functions.
992
993
Notes
994
-----
995
This includes divmod and rdivmod, whereas all_arithmetic_operators
996
does not.
997
"""
998
return request.param
999
1000
1001
_all_numeric_reductions = [
1002
"sum",
1003
"max",
1004
"min",
1005
"mean",
1006
"prod",
1007
"std",
1008
"var",
1009
"median",
1010
"kurt",
1011
"skew",
1012
]
1013
1014
1015
@pytest.fixture(params=_all_numeric_reductions)
1016
def all_numeric_reductions(request):
1017
"""
1018
Fixture for numeric reduction names.
1019
"""
1020
return request.param
1021
1022
1023
_all_boolean_reductions = ["all", "any"]
1024
1025
1026
@pytest.fixture(params=_all_boolean_reductions)
1027
def all_boolean_reductions(request):
1028
"""
1029
Fixture for boolean reduction names.
1030
"""
1031
return request.param
1032
1033
1034
_all_reductions = _all_numeric_reductions + _all_boolean_reductions
1035
1036
1037
@pytest.fixture(params=_all_reductions)
1038
def all_reductions(request):
1039
"""
1040
Fixture for all (boolean + numeric) reduction names.
1041
"""
1042
return request.param
1043
1044
1045
@pytest.fixture(
1046
params=[
1047
operator.eq,
1048
operator.ne,
1049
operator.gt,
1050
operator.ge,
1051
operator.lt,
1052
operator.le,
1053
]
1054
)
1055
def comparison_op(request):
1056
"""
1057
Fixture for operator module comparison functions.
1058
"""
1059
return request.param
1060
1061
1062
@pytest.fixture(params=["__le__", "__lt__", "__ge__", "__gt__"])
1063
def compare_operators_no_eq_ne(request):
1064
"""
1065
Fixture for dunder names for compare operations except == and !=
1066
1067
* >=
1068
* >
1069
* <
1070
* <=
1071
"""
1072
return request.param
1073
1074
1075
@pytest.fixture(
1076
params=["__and__", "__rand__", "__or__", "__ror__", "__xor__", "__rxor__"]
1077
)
1078
def all_logical_operators(request):
1079
"""
1080
Fixture for dunder names for common logical operations
1081
1082
* |
1083
* &
1084
* ^
1085
"""
1086
return request.param
1087
1088
1089
# ----------------------------------------------------------------
1090
# Data sets/files
1091
# ----------------------------------------------------------------
1092
@pytest.fixture
1093
def strict_data_files(pytestconfig):
1094
"""
1095
Returns the configuration for the test setting `--strict-data-files`.
1096
"""
1097
return pytestconfig.getoption("--strict-data-files")
1098
1099
1100
@pytest.fixture
1101
def datapath(strict_data_files):
1102
"""
1103
Get the path to a data file.
1104
1105
Parameters
1106
----------
1107
path : str
1108
Path to the file, relative to ``pandas/tests/``
1109
1110
Returns
1111
-------
1112
path including ``pandas/tests``.
1113
1114
Raises
1115
------
1116
ValueError
1117
If the path doesn't exist and the --strict-data-files option is set.
1118
"""
1119
BASE_PATH = os.path.join(os.path.dirname(__file__), "tests")
1120
1121
def deco(*args):
1122
path = os.path.join(BASE_PATH, *args)
1123
if not os.path.exists(path):
1124
if strict_data_files:
1125
raise ValueError(
1126
f"Could not find file {path} and --strict-data-files is set."
1127
)
1128
else:
1129
pytest.skip(f"Could not find {path}.")
1130
return path
1131
1132
return deco
1133
1134
1135
@pytest.fixture
1136
def iris(datapath):
1137
"""
1138
The iris dataset as a DataFrame.
1139
"""
1140
return pd.read_csv(datapath("io", "data", "csv", "iris.csv"))
1141
1142
1143
# ----------------------------------------------------------------
1144
# Time zones
1145
# ----------------------------------------------------------------
1146
TIMEZONES = [
1147
None,
1148
"UTC",
1149
"US/Eastern",
1150
"Asia/Tokyo",
1151
"dateutil/US/Pacific",
1152
"dateutil/Asia/Singapore",
1153
"+01:15",
1154
"-02:15",
1155
"UTC+01:15",
1156
"UTC-02:15",
1157
tzutc(),
1158
tzlocal(),
1159
FixedOffset(300),
1160
FixedOffset(0),
1161
FixedOffset(-300),
1162
timezone.utc,
1163
timezone(timedelta(hours=1)),
1164
timezone(timedelta(hours=-1), name="foo"),
1165
]
1166
TIMEZONE_IDS = [repr(i) for i in TIMEZONES]
1167
1168
1169
@td.parametrize_fixture_doc(str(TIMEZONE_IDS))
1170
@pytest.fixture(params=TIMEZONES, ids=TIMEZONE_IDS)
1171
def tz_naive_fixture(request):
1172
"""
1173
Fixture for trying timezones including default (None): {0}
1174
"""
1175
return request.param
1176
1177
1178
@td.parametrize_fixture_doc(str(TIMEZONE_IDS[1:]))
1179
@pytest.fixture(params=TIMEZONES[1:], ids=TIMEZONE_IDS[1:])
1180
def tz_aware_fixture(request):
1181
"""
1182
Fixture for trying explicit timezones: {0}
1183
"""
1184
return request.param
1185
1186
1187
# Generate cartesian product of tz_aware_fixture:
1188
tz_aware_fixture2 = tz_aware_fixture
1189
1190
1191
@pytest.fixture(params=["utc", "dateutil/UTC", utc, tzutc(), timezone.utc])
1192
def utc_fixture(request):
1193
"""
1194
Fixture to provide variants of UTC timezone strings and tzinfo objects.
1195
"""
1196
return request.param
1197
1198
1199
utc_fixture2 = utc_fixture
1200
1201
1202
# ----------------------------------------------------------------
1203
# Dtypes
1204
# ----------------------------------------------------------------
1205
@pytest.fixture(params=tm.STRING_DTYPES)
1206
def string_dtype(request):
1207
"""
1208
Parametrized fixture for string dtypes.
1209
1210
* str
1211
* 'str'
1212
* 'U'
1213
"""
1214
return request.param
1215
1216
1217
@pytest.fixture(
1218
params=[
1219
"string[python]",
1220
pytest.param(
1221
"string[pyarrow]", marks=td.skip_if_no("pyarrow", min_version="1.0.0")
1222
),
1223
]
1224
)
1225
def nullable_string_dtype(request):
1226
"""
1227
Parametrized fixture for string dtypes.
1228
1229
* 'string[python]'
1230
* 'string[pyarrow]'
1231
"""
1232
return request.param
1233
1234
1235
@pytest.fixture(
1236
params=[
1237
"python",
1238
pytest.param("pyarrow", marks=td.skip_if_no("pyarrow", min_version="1.0.0")),
1239
]
1240
)
1241
def string_storage(request):
1242
"""
1243
Parametrized fixture for pd.options.mode.string_storage.
1244
1245
* 'python'
1246
* 'pyarrow'
1247
"""
1248
return request.param
1249
1250
1251
# Alias so we can test with cartesian product of string_storage
1252
string_storage2 = string_storage
1253
1254
1255
@pytest.fixture(params=tm.BYTES_DTYPES)
1256
def bytes_dtype(request):
1257
"""
1258
Parametrized fixture for bytes dtypes.
1259
1260
* bytes
1261
* 'bytes'
1262
"""
1263
return request.param
1264
1265
1266
@pytest.fixture(params=tm.OBJECT_DTYPES)
1267
def object_dtype(request):
1268
"""
1269
Parametrized fixture for object dtypes.
1270
1271
* object
1272
* 'object'
1273
"""
1274
return request.param
1275
1276
1277
@pytest.fixture(
1278
params=[
1279
"object",
1280
"string[python]",
1281
pytest.param(
1282
"string[pyarrow]", marks=td.skip_if_no("pyarrow", min_version="1.0.0")
1283
),
1284
]
1285
)
1286
def any_string_dtype(request):
1287
"""
1288
Parametrized fixture for string dtypes.
1289
* 'object'
1290
* 'string[python]'
1291
* 'string[pyarrow]'
1292
"""
1293
return request.param
1294
1295
1296
@pytest.fixture(params=tm.DATETIME64_DTYPES)
1297
def datetime64_dtype(request):
1298
"""
1299
Parametrized fixture for datetime64 dtypes.
1300
1301
* 'datetime64[ns]'
1302
* 'M8[ns]'
1303
"""
1304
return request.param
1305
1306
1307
@pytest.fixture(params=tm.TIMEDELTA64_DTYPES)
1308
def timedelta64_dtype(request):
1309
"""
1310
Parametrized fixture for timedelta64 dtypes.
1311
1312
* 'timedelta64[ns]'
1313
* 'm8[ns]'
1314
"""
1315
return request.param
1316
1317
1318
@pytest.fixture
1319
def fixed_now_ts():
1320
"""
1321
Fixture emits fixed Timestamp.now()
1322
"""
1323
return Timestamp(
1324
year=2021, month=1, day=1, hour=12, minute=4, second=13, microsecond=22
1325
)
1326
1327
1328
@pytest.fixture(params=tm.FLOAT_NUMPY_DTYPES)
1329
def float_numpy_dtype(request):
1330
"""
1331
Parameterized fixture for float dtypes.
1332
1333
* float
1334
* 'float32'
1335
* 'float64'
1336
"""
1337
return request.param
1338
1339
1340
@pytest.fixture(params=tm.FLOAT_EA_DTYPES)
1341
def float_ea_dtype(request):
1342
"""
1343
Parameterized fixture for float dtypes.
1344
1345
* 'Float32'
1346
* 'Float64'
1347
"""
1348
return request.param
1349
1350
1351
@pytest.fixture(params=tm.FLOAT_NUMPY_DTYPES + tm.FLOAT_EA_DTYPES)
1352
def any_float_dtype(request):
1353
"""
1354
Parameterized fixture for float dtypes.
1355
1356
* float
1357
* 'float32'
1358
* 'float64'
1359
* 'Float32'
1360
* 'Float64'
1361
"""
1362
return request.param
1363
1364
1365
@pytest.fixture(params=tm.COMPLEX_DTYPES)
1366
def complex_dtype(request):
1367
"""
1368
Parameterized fixture for complex dtypes.
1369
1370
* complex
1371
* 'complex64'
1372
* 'complex128'
1373
"""
1374
return request.param
1375
1376
1377
@pytest.fixture(params=tm.SIGNED_INT_NUMPY_DTYPES)
1378
def any_signed_int_numpy_dtype(request):
1379
"""
1380
Parameterized fixture for signed integer dtypes.
1381
1382
* int
1383
* 'int8'
1384
* 'int16'
1385
* 'int32'
1386
* 'int64'
1387
"""
1388
return request.param
1389
1390
1391
@pytest.fixture(params=tm.UNSIGNED_INT_NUMPY_DTYPES)
1392
def any_unsigned_int_numpy_dtype(request):
1393
"""
1394
Parameterized fixture for unsigned integer dtypes.
1395
1396
* 'uint8'
1397
* 'uint16'
1398
* 'uint32'
1399
* 'uint64'
1400
"""
1401
return request.param
1402
1403
1404
@pytest.fixture(params=tm.ALL_INT_NUMPY_DTYPES)
1405
def any_int_numpy_dtype(request):
1406
"""
1407
Parameterized fixture for any integer dtype.
1408
1409
* int
1410
* 'int8'
1411
* 'uint8'
1412
* 'int16'
1413
* 'uint16'
1414
* 'int32'
1415
* 'uint32'
1416
* 'int64'
1417
* 'uint64'
1418
"""
1419
return request.param
1420
1421
1422
@pytest.fixture(params=tm.ALL_INT_EA_DTYPES)
1423
def any_int_ea_dtype(request):
1424
"""
1425
Parameterized fixture for any nullable integer dtype.
1426
1427
* 'UInt8'
1428
* 'Int8'
1429
* 'UInt16'
1430
* 'Int16'
1431
* 'UInt32'
1432
* 'Int32'
1433
* 'UInt64'
1434
* 'Int64'
1435
"""
1436
return request.param
1437
1438
1439
@pytest.fixture(params=tm.ALL_INT_NUMPY_DTYPES + tm.ALL_INT_EA_DTYPES)
1440
def any_int_dtype(request):
1441
"""
1442
Parameterized fixture for any nullable integer dtype.
1443
1444
* int
1445
* 'int8'
1446
* 'uint8'
1447
* 'int16'
1448
* 'uint16'
1449
* 'int32'
1450
* 'uint32'
1451
* 'int64'
1452
* 'uint64'
1453
* 'UInt8'
1454
* 'Int8'
1455
* 'UInt16'
1456
* 'Int16'
1457
* 'UInt32'
1458
* 'Int32'
1459
* 'UInt64'
1460
* 'Int64'
1461
"""
1462
return request.param
1463
1464
1465
@pytest.fixture(params=tm.ALL_INT_EA_DTYPES + tm.FLOAT_EA_DTYPES)
1466
def any_numeric_ea_dtype(request):
1467
"""
1468
Parameterized fixture for any nullable integer dtype and
1469
any float ea dtypes.
1470
1471
* 'UInt8'
1472
* 'Int8'
1473
* 'UInt16'
1474
* 'Int16'
1475
* 'UInt32'
1476
* 'Int32'
1477
* 'UInt64'
1478
* 'Int64'
1479
* 'Float32'
1480
* 'Float64'
1481
"""
1482
return request.param
1483
1484
1485
@pytest.fixture(params=tm.SIGNED_INT_EA_DTYPES)
1486
def any_signed_int_ea_dtype(request):
1487
"""
1488
Parameterized fixture for any signed nullable integer dtype.
1489
1490
* 'Int8'
1491
* 'Int16'
1492
* 'Int32'
1493
* 'Int64'
1494
"""
1495
return request.param
1496
1497
1498
@pytest.fixture(params=tm.ALL_REAL_NUMPY_DTYPES)
1499
def any_real_numpy_dtype(request):
1500
"""
1501
Parameterized fixture for any (purely) real numeric dtype.
1502
1503
* int
1504
* 'int8'
1505
* 'uint8'
1506
* 'int16'
1507
* 'uint16'
1508
* 'int32'
1509
* 'uint32'
1510
* 'int64'
1511
* 'uint64'
1512
* float
1513
* 'float32'
1514
* 'float64'
1515
"""
1516
return request.param
1517
1518
1519
@pytest.fixture(params=tm.ALL_NUMPY_DTYPES)
1520
def any_numpy_dtype(request):
1521
"""
1522
Parameterized fixture for all numpy dtypes.
1523
1524
* bool
1525
* 'bool'
1526
* int
1527
* 'int8'
1528
* 'uint8'
1529
* 'int16'
1530
* 'uint16'
1531
* 'int32'
1532
* 'uint32'
1533
* 'int64'
1534
* 'uint64'
1535
* float
1536
* 'float32'
1537
* 'float64'
1538
* complex
1539
* 'complex64'
1540
* 'complex128'
1541
* str
1542
* 'str'
1543
* 'U'
1544
* bytes
1545
* 'bytes'
1546
* 'datetime64[ns]'
1547
* 'M8[ns]'
1548
* 'timedelta64[ns]'
1549
* 'm8[ns]'
1550
* object
1551
* 'object'
1552
"""
1553
return request.param
1554
1555
1556
# categoricals are handled separately
1557
_any_skipna_inferred_dtype = [
1558
("string", ["a", np.nan, "c"]),
1559
("string", ["a", pd.NA, "c"]),
1560
("bytes", [b"a", np.nan, b"c"]),
1561
("empty", [np.nan, np.nan, np.nan]),
1562
("empty", []),
1563
("mixed-integer", ["a", np.nan, 2]),
1564
("mixed", ["a", np.nan, 2.0]),
1565
("floating", [1.0, np.nan, 2.0]),
1566
("integer", [1, np.nan, 2]),
1567
("mixed-integer-float", [1, np.nan, 2.0]),
1568
("decimal", [Decimal(1), np.nan, Decimal(2)]),
1569
("boolean", [True, np.nan, False]),
1570
("boolean", [True, pd.NA, False]),
1571
("datetime64", [np.datetime64("2013-01-01"), np.nan, np.datetime64("2018-01-01")]),
1572
("datetime", [Timestamp("20130101"), np.nan, Timestamp("20180101")]),
1573
("date", [date(2013, 1, 1), np.nan, date(2018, 1, 1)]),
1574
# The following two dtypes are commented out due to GH 23554
1575
# ('complex', [1 + 1j, np.nan, 2 + 2j]),
1576
# ('timedelta64', [np.timedelta64(1, 'D'),
1577
# np.nan, np.timedelta64(2, 'D')]),
1578
("timedelta", [timedelta(1), np.nan, timedelta(2)]),
1579
("time", [time(1), np.nan, time(2)]),
1580
("period", [Period(2013), pd.NaT, Period(2018)]),
1581
("interval", [Interval(0, 1), np.nan, Interval(0, 2)]),
1582
]
1583
ids, _ = zip(*_any_skipna_inferred_dtype) # use inferred type as fixture-id
1584
1585
1586
@pytest.fixture(params=_any_skipna_inferred_dtype, ids=ids)
1587
def any_skipna_inferred_dtype(request):
1588
"""
1589
Fixture for all inferred dtypes from _libs.lib.infer_dtype
1590
1591
The covered (inferred) types are:
1592
* 'string'
1593
* 'empty'
1594
* 'bytes'
1595
* 'mixed'
1596
* 'mixed-integer'
1597
* 'mixed-integer-float'
1598
* 'floating'
1599
* 'integer'
1600
* 'decimal'
1601
* 'boolean'
1602
* 'datetime64'
1603
* 'datetime'
1604
* 'date'
1605
* 'timedelta'
1606
* 'time'
1607
* 'period'
1608
* 'interval'
1609
1610
Returns
1611
-------
1612
inferred_dtype : str
1613
The string for the inferred dtype from _libs.lib.infer_dtype
1614
values : np.ndarray
1615
An array of object dtype that will be inferred to have
1616
`inferred_dtype`
1617
1618
Examples
1619
--------
1620
>>> import pandas._libs.lib as lib
1621
>>>
1622
>>> def test_something(any_skipna_inferred_dtype):
1623
... inferred_dtype, values = any_skipna_inferred_dtype
1624
... # will pass
1625
... assert lib.infer_dtype(values, skipna=True) == inferred_dtype
1626
"""
1627
inferred_dtype, values = request.param
1628
values = np.array(values, dtype=object) # object dtype to avoid casting
1629
1630
# correctness of inference tested in tests/dtypes/test_inference.py
1631
return inferred_dtype, values
1632
1633
1634
# ----------------------------------------------------------------
1635
# Misc
1636
# ----------------------------------------------------------------
1637
@pytest.fixture
1638
def ip():
1639
"""
1640
Get an instance of IPython.InteractiveShell.
1641
1642
Will raise a skip if IPython is not installed.
1643
"""
1644
pytest.importorskip("IPython", minversion="6.0.0")
1645
from IPython.core.interactiveshell import InteractiveShell
1646
1647
# GH#35711 make sure sqlite history file handle is not leaked
1648
from traitlets.config import Config # isort:skip
1649
1650
c = Config()
1651
c.HistoryManager.hist_file = ":memory:"
1652
1653
return InteractiveShell(config=c)
1654
1655
1656
@pytest.fixture(params=["bsr", "coo", "csc", "csr", "dia", "dok", "lil"])
1657
def spmatrix(request):
1658
"""
1659
Yields scipy sparse matrix classes.
1660
"""
1661
from scipy import sparse
1662
1663
return getattr(sparse, request.param + "_matrix")
1664
1665
1666
@pytest.fixture(
1667
params=[
1668
getattr(pd.offsets, o)
1669
for o in pd.offsets.__all__
1670
if issubclass(getattr(pd.offsets, o), pd.offsets.Tick)
1671
]
1672
)
1673
def tick_classes(request):
1674
"""
1675
Fixture for Tick based datetime offsets available for a time series.
1676
"""
1677
return request.param
1678
1679
1680
@pytest.fixture(params=[None, lambda x: x])
1681
def sort_by_key(request):
1682
"""
1683
Simple fixture for testing keys in sorting methods.
1684
Tests None (no key) and the identity key.
1685
"""
1686
return request.param
1687
1688
1689
@pytest.fixture()
1690
def fsspectest():
1691
pytest.importorskip("fsspec")
1692
from fsspec import register_implementation
1693
from fsspec.implementations.memory import MemoryFileSystem
1694
from fsspec.registry import _registry as registry
1695
1696
class TestMemoryFS(MemoryFileSystem):
1697
protocol = "testmem"
1698
test = [None]
1699
1700
def __init__(self, **kwargs):
1701
self.test[0] = kwargs.pop("test", None)
1702
super().__init__(**kwargs)
1703
1704
register_implementation("testmem", TestMemoryFS, clobber=True)
1705
yield TestMemoryFS()
1706
registry.pop("testmem", None)
1707
TestMemoryFS.test[0] = None
1708
TestMemoryFS.store.clear()
1709
1710
1711
@pytest.fixture(
1712
params=[
1713
("foo", None, None),
1714
("Egon", "Venkman", None),
1715
("NCC1701D", "NCC1701D", "NCC1701D"),
1716
# possibly-matching NAs
1717
(np.nan, np.nan, np.nan),
1718
(np.nan, pd.NaT, None),
1719
(np.nan, pd.NA, None),
1720
(pd.NA, pd.NA, pd.NA),
1721
]
1722
)
1723
def names(request):
1724
"""
1725
A 3-tuple of names, the first two for operands, the last for a result.
1726
"""
1727
return request.param
1728
1729
1730
@pytest.fixture(params=[tm.setitem, tm.loc, tm.iloc])
1731
def indexer_sli(request):
1732
"""
1733
Parametrize over __setitem__, loc.__setitem__, iloc.__setitem__
1734
"""
1735
return request.param
1736
1737
1738
@pytest.fixture(params=[tm.setitem, tm.iloc])
1739
def indexer_si(request):
1740
"""
1741
Parametrize over __setitem__, iloc.__setitem__
1742
"""
1743
return request.param
1744
1745
1746
@pytest.fixture(params=[tm.setitem, tm.loc])
1747
def indexer_sl(request):
1748
"""
1749
Parametrize over __setitem__, loc.__setitem__
1750
"""
1751
return request.param
1752
1753
1754
@pytest.fixture(params=[tm.at, tm.loc])
1755
def indexer_al(request):
1756
"""
1757
Parametrize over at.__setitem__, loc.__setitem__
1758
"""
1759
return request.param
1760
1761
1762
@pytest.fixture(params=[tm.iat, tm.iloc])
1763
def indexer_ial(request):
1764
"""
1765
Parametrize over iat.__setitem__, iloc.__setitem__
1766
"""
1767
return request.param
1768
1769
1770
@pytest.fixture
1771
def using_array_manager(request):
1772
"""
1773
Fixture to check if the array manager is being used.
1774
"""
1775
return pd.options.mode.data_manager == "array"
1776
1777