test.source
28.4 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
commit b5a5268dabb2a4dea1c3c543a1ddff501b87a447
Author: jbrockmendel <jbrockmendel@gmail.com>
Date: Tue Sep 8 18:33:41 2020 -0700
STY: De-privatize imported names (#36235)
diff --git a/pandas/_libs/interval.pyx b/pandas/_libs/interval.pyx
index 931ad8326..f8bcbcfb1 100644
--- a/pandas/_libs/interval.pyx
+++ b/pandas/_libs/interval.pyx
@@ -46,7 +46,7 @@ from pandas._libs.tslibs.util cimport (
is_timedelta64_object,
)
-_VALID_CLOSED = frozenset(['left', 'right', 'both', 'neither'])
+VALID_CLOSED = frozenset(['left', 'right', 'both', 'neither'])
cdef class IntervalMixin:
@@ -318,7 +318,7 @@ cdef class Interval(IntervalMixin):
self._validate_endpoint(left)
self._validate_endpoint(right)
- if closed not in _VALID_CLOSED:
+ if closed not in VALID_CLOSED:
raise ValueError(f"invalid option for 'closed': {closed}")
if not left <= right:
raise ValueError("left side of interval must be <= right side")
diff --git a/pandas/core/arrays/_arrow_utils.py b/pandas/core/arrays/_arrow_utils.py
index 4a33e0e84..c89f5554d 100644
--- a/pandas/core/arrays/_arrow_utils.py
+++ b/pandas/core/arrays/_arrow_utils.py
@@ -4,7 +4,7 @@ import json
import numpy as np
import pyarrow
-from pandas.core.arrays.interval import _VALID_CLOSED
+from pandas.core.arrays.interval import VALID_CLOSED
_pyarrow_version_ge_015 = LooseVersion(pyarrow.__version__) >= LooseVersion("0.15")
@@ -83,7 +83,7 @@ if _pyarrow_version_ge_015:
def __init__(self, subtype, closed):
# attributes need to be set first before calling
# super init (as that calls serialize)
- assert closed in _VALID_CLOSED
+ assert closed in VALID_CLOSED
self._closed = closed
if not isinstance(subtype, pyarrow.DataType):
subtype = pyarrow.type_for_alias(str(subtype))
diff --git a/pandas/core/arrays/interval.py b/pandas/core/arrays/interval.py
index d76e0fd62..1dbd3cfc6 100644
--- a/pandas/core/arrays/interval.py
+++ b/pandas/core/arrays/interval.py
@@ -5,7 +5,12 @@ import numpy as np
from pandas._config import get_option
-from pandas._libs.interval import Interval, IntervalMixin, intervals_to_interval_bounds
+from pandas._libs.interval import (
+ VALID_CLOSED,
+ Interval,
+ IntervalMixin,
+ intervals_to_interval_bounds,
+)
from pandas.compat.numpy import function as nv
from pandas.util._decorators import Appender
@@ -42,7 +47,6 @@ from pandas.core.construction import array
from pandas.core.indexers import check_array_indexer
from pandas.core.indexes.base import ensure_index
-_VALID_CLOSED = {"left", "right", "both", "neither"}
_interval_shared_docs = {}
_shared_docs_kwargs = dict(
@@ -475,7 +479,7 @@ class IntervalArray(IntervalMixin, ExtensionArray):
* left and right have the same missing values
* left is always below right
"""
- if self.closed not in _VALID_CLOSED:
+ if self.closed not in VALID_CLOSED:
msg = f"invalid option for 'closed': {self.closed}"
raise ValueError(msg)
if len(self.left) != len(self.right):
@@ -1012,7 +1016,7 @@ class IntervalArray(IntervalMixin, ExtensionArray):
)
)
def set_closed(self, closed):
- if closed not in _VALID_CLOSED:
+ if closed not in VALID_CLOSED:
msg = f"invalid option for 'closed': {closed}"
raise ValueError(msg)
diff --git a/pandas/core/arrays/sparse/__init__.py b/pandas/core/arrays/sparse/__init__.py
index e928db499..e9ff4b7d4 100644
--- a/pandas/core/arrays/sparse/__init__.py
+++ b/pandas/core/arrays/sparse/__init__.py
@@ -5,6 +5,6 @@ from pandas.core.arrays.sparse.array import (
BlockIndex,
IntIndex,
SparseArray,
- _make_index,
+ make_sparse_index,
)
from pandas.core.arrays.sparse.dtype import SparseDtype
diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py
index 47c960dc9..853f7bb0b 100644
--- a/pandas/core/arrays/sparse/array.py
+++ b/pandas/core/arrays/sparse/array.py
@@ -1556,7 +1556,7 @@ def make_sparse(arr: np.ndarray, kind="block", fill_value=None, dtype=None, copy
else:
indices = mask.nonzero()[0].astype(np.int32)
- index = _make_index(length, indices, kind)
+ index = make_sparse_index(length, indices, kind)
sparsified_values = arr[mask]
if dtype is not None:
sparsified_values = astype_nansafe(sparsified_values, dtype=dtype)
@@ -1564,7 +1564,7 @@ def make_sparse(arr: np.ndarray, kind="block", fill_value=None, dtype=None, copy
return sparsified_values, index, fill_value
-def _make_index(length, indices, kind):
+def make_sparse_index(length, indices, kind):
if kind == "block" or isinstance(kind, BlockIndex):
locs, lens = splib.get_blocks(indices)
diff --git a/pandas/core/computation/engines.py b/pandas/core/computation/engines.py
index 0cdc0f530..77a378369 100644
--- a/pandas/core/computation/engines.py
+++ b/pandas/core/computation/engines.py
@@ -130,7 +130,7 @@ class PythonEngine(AbstractEngine):
pass
-_engines: Dict[str, Type[AbstractEngine]] = {
+ENGINES: Dict[str, Type[AbstractEngine]] = {
"numexpr": NumExprEngine,
"python": PythonEngine,
}
diff --git a/pandas/core/computation/eval.py b/pandas/core/computation/eval.py
index f6a793514..630606b4d 100644
--- a/pandas/core/computation/eval.py
+++ b/pandas/core/computation/eval.py
@@ -9,8 +9,8 @@ import warnings
from pandas._libs.lib import no_default
from pandas.util._validators import validate_bool_kwarg
-from pandas.core.computation.engines import _engines
-from pandas.core.computation.expr import Expr, _parsers
+from pandas.core.computation.engines import ENGINES
+from pandas.core.computation.expr import PARSERS, Expr
from pandas.core.computation.parsing import tokenize_string
from pandas.core.computation.scope import ensure_scope
@@ -43,8 +43,8 @@ def _check_engine(engine: Optional[str]) -> str:
if engine is None:
engine = "numexpr" if NUMEXPR_INSTALLED else "python"
- if engine not in _engines:
- valid_engines = list(_engines.keys())
+ if engine not in ENGINES:
+ valid_engines = list(ENGINES.keys())
raise KeyError(
f"Invalid engine '{engine}' passed, valid engines are {valid_engines}"
)
@@ -75,9 +75,9 @@ def _check_parser(parser: str):
KeyError
* If an invalid parser is passed
"""
- if parser not in _parsers:
+ if parser not in PARSERS:
raise KeyError(
- f"Invalid parser '{parser}' passed, valid parsers are {_parsers.keys()}"
+ f"Invalid parser '{parser}' passed, valid parsers are {PARSERS.keys()}"
)
@@ -341,7 +341,7 @@ def eval(
parsed_expr = Expr(expr, engine=engine, parser=parser, env=env)
# construct the engine and evaluate the parsed expression
- eng = _engines[engine]
+ eng = ENGINES[engine]
eng_inst = eng(parsed_expr)
ret = eng_inst.evaluate()
diff --git a/pandas/core/computation/expr.py b/pandas/core/computation/expr.py
index 8cff6abc0..f5897277d 100644
--- a/pandas/core/computation/expr.py
+++ b/pandas/core/computation/expr.py
@@ -782,7 +782,7 @@ class Expr:
self.env = env or Scope(level=level + 1)
self.engine = engine
self.parser = parser
- self._visitor = _parsers[parser](self.env, self.engine, self.parser)
+ self._visitor = PARSERS[parser](self.env, self.engine, self.parser)
self.terms = self.parse()
@property
@@ -814,4 +814,4 @@ class Expr:
return frozenset(term.name for term in com.flatten(self.terms))
-_parsers = {"python": PythonExprVisitor, "pandas": PandasExprVisitor}
+PARSERS = {"python": PythonExprVisitor, "pandas": PandasExprVisitor}
diff --git a/pandas/core/config_init.py b/pandas/core/config_init.py
index 0c23f1b4b..bfe20551c 100644
--- a/pandas/core/config_init.py
+++ b/pandas/core/config_init.py
@@ -314,9 +314,9 @@ pc_latex_multirow = """
def table_schema_cb(key):
- from pandas.io.formats.printing import _enable_data_resource_formatter
+ from pandas.io.formats.printing import enable_data_resource_formatter
- _enable_data_resource_formatter(cf.get_option(key))
+ enable_data_resource_formatter(cf.get_option(key))
def is_terminal() -> bool:
diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py
index 72003eab2..e870187fc 100644
--- a/pandas/core/groupby/generic.py
+++ b/pandas/core/groupby/generic.py
@@ -70,9 +70,9 @@ from pandas.core.groupby.groupby import (
GroupBy,
_agg_template,
_apply_docs,
- _group_selection_context,
_transform_template,
get_groupby,
+ group_selection_context,
)
from pandas.core.groupby.numba_ import generate_numba_func, split_for_numba
from pandas.core.indexes.api import Index, MultiIndex, all_indexes_same
@@ -230,7 +230,7 @@ class SeriesGroupBy(GroupBy[Series]):
raise NotImplementedError(
"Numba engine can only be used with a single function."
)
- with _group_selection_context(self):
+ with group_selection_context(self):
data = self._selected_obj
result, index = self._aggregate_with_numba(
data.to_frame(), func, *args, engine_kwargs=engine_kwargs, **kwargs
@@ -685,7 +685,7 @@ class SeriesGroupBy(GroupBy[Series]):
self, normalize=False, sort=True, ascending=False, bins=None, dropna=True
):
- from pandas.core.reshape.merge import _get_join_indexers
+ from pandas.core.reshape.merge import get_join_indexers
from pandas.core.reshape.tile import cut
if bins is not None and not np.iterable(bins):
@@ -787,7 +787,7 @@ class SeriesGroupBy(GroupBy[Series]):
right = [diff.cumsum() - 1, codes[-1]]
- _, idx = _get_join_indexers(left, right, sort=False, how="left")
+ _, idx = get_join_indexers(left, right, sort=False, how="left")
out = np.where(idx != -1, out[idx], 0)
if sort:
@@ -942,7 +942,7 @@ class DataFrameGroupBy(GroupBy[DataFrame]):
raise NotImplementedError(
"Numba engine can only be used with a single function."
)
- with _group_selection_context(self):
+ with group_selection_context(self):
data = self._selected_obj
result, index = self._aggregate_with_numba(
data, func, *args, engine_kwargs=engine_kwargs, **kwargs
diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py
index 6ef2e6703..1e3e56f4f 100644
--- a/pandas/core/groupby/groupby.py
+++ b/pandas/core/groupby/groupby.py
@@ -459,9 +459,9 @@ class GroupByPlot(PandasObject):
@contextmanager
-def _group_selection_context(groupby: "_GroupBy"):
+def group_selection_context(groupby: "_GroupBy"):
"""
- Set / reset the _group_selection_context.
+ Set / reset the group_selection_context.
"""
groupby._set_group_selection()
try:
@@ -737,7 +737,7 @@ b 2""",
def _make_wrapper(self, name: str) -> Callable:
assert name in self._apply_allowlist
- with _group_selection_context(self):
+ with group_selection_context(self):
# need to setup the selection
# as are not passed directly but in the grouper
f = getattr(self._obj_with_exclusions, name)
@@ -868,7 +868,7 @@ b 2""",
# fails on *some* columns, e.g. a numeric operation
# on a string grouper column
- with _group_selection_context(self):
+ with group_selection_context(self):
return self._python_apply_general(f, self._selected_obj)
return result
@@ -994,7 +994,7 @@ b 2""",
alias: str,
npfunc: Callable,
):
- with _group_selection_context(self):
+ with group_selection_context(self):
# try a cython aggregation if we can
try:
return self._cython_agg_general(
@@ -1499,7 +1499,7 @@ class GroupBy(_GroupBy[FrameOrSeries]):
)
else:
func = lambda x: x.var(ddof=ddof)
- with _group_selection_context(self):
+ with group_selection_context(self):
return self._python_agg_general(func)
@Substitution(name="groupby")
@@ -1658,7 +1658,7 @@ class GroupBy(_GroupBy[FrameOrSeries]):
@doc(DataFrame.describe)
def describe(self, **kwargs):
- with _group_selection_context(self):
+ with group_selection_context(self):
result = self.apply(lambda x: x.describe(**kwargs))
if self.axis == 1:
return result.T
@@ -1963,7 +1963,7 @@ class GroupBy(_GroupBy[FrameOrSeries]):
nth_values = list(set(n))
nth_array = np.array(nth_values, dtype=np.intp)
- with _group_selection_context(self):
+ with group_selection_context(self):
mask_left = np.in1d(self._cumcount_array(), nth_array)
mask_right = np.in1d(
@@ -2226,7 +2226,7 @@ class GroupBy(_GroupBy[FrameOrSeries]):
5 0
dtype: int64
"""
- with _group_selection_context(self):
+ with group_selection_context(self):
index = self._selected_obj.index
result = self._obj_1d_constructor(self.grouper.group_info[0], index)
if not ascending:
@@ -2287,7 +2287,7 @@ class GroupBy(_GroupBy[FrameOrSeries]):
5 0
dtype: int64
"""
- with _group_selection_context(self):
+ with group_selection_context(self):
index = self._selected_obj.index
cumcounts = self._cumcount_array(ascending=ascending)
return self._obj_1d_constructor(cumcounts, index)
diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py
index 526dae7e2..8014b16d0 100644
--- a/pandas/core/indexes/base.py
+++ b/pandas/core/indexes/base.py
@@ -3660,7 +3660,7 @@ class Index(IndexOpsMixin, PandasObject):
return result
def _join_non_unique(self, other, how="left", return_indexers=False):
- from pandas.core.reshape.merge import _get_join_indexers
+ from pandas.core.reshape.merge import get_join_indexers
# We only get here if dtypes match
assert self.dtype == other.dtype
@@ -3668,7 +3668,7 @@ class Index(IndexOpsMixin, PandasObject):
lvalues = self._get_engine_target()
rvalues = other._get_engine_target()
- left_idx, right_idx = _get_join_indexers(
+ left_idx, right_idx = get_join_indexers(
[lvalues], [rvalues], how=how, sort=True
)
diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py
index 3f72577c9..154f41bf0 100644
--- a/pandas/core/indexes/interval.py
+++ b/pandas/core/indexes/interval.py
@@ -59,7 +59,6 @@ from pandas.core.ops import get_op_result_name
if TYPE_CHECKING:
from pandas import CategoricalIndex # noqa:F401
-_VALID_CLOSED = {"left", "right", "both", "neither"}
_index_doc_kwargs = dict(ibase._index_doc_kwargs)
_index_doc_kwargs.update(
diff --git a/pandas/core/reshape/merge.py b/pandas/core/reshape/merge.py
index 030dec369..9f19ea9ae 100644
--- a/pandas/core/reshape/merge.py
+++ b/pandas/core/reshape/merge.py
@@ -859,7 +859,7 @@ class _MergeOperation:
def _get_join_indexers(self):
""" return the join indexers """
- return _get_join_indexers(
+ return get_join_indexers(
self.left_join_keys, self.right_join_keys, sort=self.sort, how=self.how
)
@@ -1298,7 +1298,7 @@ class _MergeOperation:
raise ValueError("Not a valid argument for validate")
-def _get_join_indexers(
+def get_join_indexers(
left_keys, right_keys, sort: bool = False, how: str = "inner", **kwargs
):
"""
diff --git a/pandas/io/formats/printing.py b/pandas/io/formats/printing.py
index edc6fbfff..0d2ca83f1 100644
--- a/pandas/io/formats/printing.py
+++ b/pandas/io/formats/printing.py
@@ -243,7 +243,7 @@ def pprint_thing_encoded(
return value.encode(encoding, errors)
-def _enable_data_resource_formatter(enable: bool) -> None:
+def enable_data_resource_formatter(enable: bool) -> None:
if "IPython" not in sys.modules:
# definitely not in IPython
return
diff --git a/pandas/tests/arrays/sparse/test_libsparse.py b/pandas/tests/arrays/sparse/test_libsparse.py
index a2f861d37..2d6e657de 100644
--- a/pandas/tests/arrays/sparse/test_libsparse.py
+++ b/pandas/tests/arrays/sparse/test_libsparse.py
@@ -8,7 +8,7 @@ import pandas.util._test_decorators as td
from pandas import Series
import pandas._testing as tm
-from pandas.core.arrays.sparse import BlockIndex, IntIndex, _make_index
+from pandas.core.arrays.sparse import BlockIndex, IntIndex, make_sparse_index
TEST_LENGTH = 20
@@ -273,41 +273,43 @@ class TestSparseIndexIntersect:
class TestSparseIndexCommon:
def test_int_internal(self):
- idx = _make_index(4, np.array([2, 3], dtype=np.int32), kind="integer")
+ idx = make_sparse_index(4, np.array([2, 3], dtype=np.int32), kind="integer")
assert isinstance(idx, IntIndex)
assert idx.npoints == 2
tm.assert_numpy_array_equal(idx.indices, np.array([2, 3], dtype=np.int32))
- idx = _make_index(4, np.array([], dtype=np.int32), kind="integer")
+ idx = make_sparse_index(4, np.array([], dtype=np.int32), kind="integer")
assert isinstance(idx, IntIndex)
assert idx.npoints == 0
tm.assert_numpy_array_equal(idx.indices, np.array([], dtype=np.int32))
- idx = _make_index(4, np.array([0, 1, 2, 3], dtype=np.int32), kind="integer")
+ idx = make_sparse_index(
+ 4, np.array([0, 1, 2, 3], dtype=np.int32), kind="integer"
+ )
assert isinstance(idx, IntIndex)
assert idx.npoints == 4
tm.assert_numpy_array_equal(idx.indices, np.array([0, 1, 2, 3], dtype=np.int32))
def test_block_internal(self):
- idx = _make_index(4, np.array([2, 3], dtype=np.int32), kind="block")
+ idx = make_sparse_index(4, np.array([2, 3], dtype=np.int32), kind="block")
assert isinstance(idx, BlockIndex)
assert idx.npoints == 2
tm.assert_numpy_array_equal(idx.blocs, np.array([2], dtype=np.int32))
tm.assert_numpy_array_equal(idx.blengths, np.array([2], dtype=np.int32))
- idx = _make_index(4, np.array([], dtype=np.int32), kind="block")
+ idx = make_sparse_index(4, np.array([], dtype=np.int32), kind="block")
assert isinstance(idx, BlockIndex)
assert idx.npoints == 0
tm.assert_numpy_array_equal(idx.blocs, np.array([], dtype=np.int32))
tm.assert_numpy_array_equal(idx.blengths, np.array([], dtype=np.int32))
- idx = _make_index(4, np.array([0, 1, 2, 3], dtype=np.int32), kind="block")
+ idx = make_sparse_index(4, np.array([0, 1, 2, 3], dtype=np.int32), kind="block")
assert isinstance(idx, BlockIndex)
assert idx.npoints == 4
tm.assert_numpy_array_equal(idx.blocs, np.array([0], dtype=np.int32))
tm.assert_numpy_array_equal(idx.blengths, np.array([4], dtype=np.int32))
- idx = _make_index(4, np.array([0, 2, 3], dtype=np.int32), kind="block")
+ idx = make_sparse_index(4, np.array([0, 2, 3], dtype=np.int32), kind="block")
assert isinstance(idx, BlockIndex)
assert idx.npoints == 3
tm.assert_numpy_array_equal(idx.blocs, np.array([0, 2], dtype=np.int32))
@@ -315,7 +317,7 @@ class TestSparseIndexCommon:
def test_lookup(self):
for kind in ["integer", "block"]:
- idx = _make_index(4, np.array([2, 3], dtype=np.int32), kind=kind)
+ idx = make_sparse_index(4, np.array([2, 3], dtype=np.int32), kind=kind)
assert idx.lookup(-1) == -1
assert idx.lookup(0) == -1
assert idx.lookup(1) == -1
@@ -323,12 +325,14 @@ class TestSparseIndexCommon:
assert idx.lookup(3) == 1
assert idx.lookup(4) == -1
- idx = _make_index(4, np.array([], dtype=np.int32), kind=kind)
+ idx = make_sparse_index(4, np.array([], dtype=np.int32), kind=kind)
for i in range(-1, 5):
assert idx.lookup(i) == -1
- idx = _make_index(4, np.array([0, 1, 2, 3], dtype=np.int32), kind=kind)
+ idx = make_sparse_index(
+ 4, np.array([0, 1, 2, 3], dtype=np.int32), kind=kind
+ )
assert idx.lookup(-1) == -1
assert idx.lookup(0) == 0
assert idx.lookup(1) == 1
@@ -336,7 +340,7 @@ class TestSparseIndexCommon:
assert idx.lookup(3) == 3
assert idx.lookup(4) == -1
- idx = _make_index(4, np.array([0, 2, 3], dtype=np.int32), kind=kind)
+ idx = make_sparse_index(4, np.array([0, 2, 3], dtype=np.int32), kind=kind)
assert idx.lookup(-1) == -1
assert idx.lookup(0) == 0
assert idx.lookup(1) == -1
@@ -346,7 +350,7 @@ class TestSparseIndexCommon:
def test_lookup_array(self):
for kind in ["integer", "block"]:
- idx = _make_index(4, np.array([2, 3], dtype=np.int32), kind=kind)
+ idx = make_sparse_index(4, np.array([2, 3], dtype=np.int32), kind=kind)
res = idx.lookup_array(np.array([-1, 0, 2], dtype=np.int32))
exp = np.array([-1, -1, 0], dtype=np.int32)
@@ -356,11 +360,13 @@ class TestSparseIndexCommon:
exp = np.array([-1, 0, -1, 1], dtype=np.int32)
tm.assert_numpy_array_equal(res, exp)
- idx = _make_index(4, np.array([], dtype=np.int32), kind=kind)
+ idx = make_sparse_index(4, np.array([], dtype=np.int32), kind=kind)
res = idx.lookup_array(np.array([-1, 0, 2, 4], dtype=np.int32))
exp = np.array([-1, -1, -1, -1], dtype=np.int32)
- idx = _make_index(4, np.array([0, 1, 2, 3], dtype=np.int32), kind=kind)
+ idx = make_sparse_index(
+ 4, np.array([0, 1, 2, 3], dtype=np.int32), kind=kind
+ )
res = idx.lookup_array(np.array([-1, 0, 2], dtype=np.int32))
exp = np.array([-1, 0, 2], dtype=np.int32)
tm.assert_numpy_array_equal(res, exp)
@@ -369,7 +375,7 @@ class TestSparseIndexCommon:
exp = np.array([-1, 2, 1, 3], dtype=np.int32)
tm.assert_numpy_array_equal(res, exp)
- idx = _make_index(4, np.array([0, 2, 3], dtype=np.int32), kind=kind)
+ idx = make_sparse_index(4, np.array([0, 2, 3], dtype=np.int32), kind=kind)
res = idx.lookup_array(np.array([2, 1, 3, 0], dtype=np.int32))
exp = np.array([1, -1, 2, 0], dtype=np.int32)
tm.assert_numpy_array_equal(res, exp)
@@ -402,25 +408,25 @@ class TestSparseIndexCommon:
class TestBlockIndex:
def test_block_internal(self):
- idx = _make_index(4, np.array([2, 3], dtype=np.int32), kind="block")
+ idx = make_sparse_index(4, np.array([2, 3], dtype=np.int32), kind="block")
assert isinstance(idx, BlockIndex)
assert idx.npoints == 2
tm.assert_numpy_array_equal(idx.blocs, np.array([2], dtype=np.int32))
tm.assert_numpy_array_equal(idx.blengths, np.array([2], dtype=np.int32))
- idx = _make_index(4, np.array([], dtype=np.int32), kind="block")
+ idx = make_sparse_index(4, np.array([], dtype=np.int32), kind="block")
assert isinstance(idx, BlockIndex)
assert idx.npoints == 0
tm.assert_numpy_array_equal(idx.blocs, np.array([], dtype=np.int32))
tm.assert_numpy_array_equal(idx.blengths, np.array([], dtype=np.int32))
- idx = _make_index(4, np.array([0, 1, 2, 3], dtype=np.int32), kind="block")
+ idx = make_sparse_index(4, np.array([0, 1, 2, 3], dtype=np.int32), kind="block")
assert isinstance(idx, BlockIndex)
assert idx.npoints == 4
tm.assert_numpy_array_equal(idx.blocs, np.array([0], dtype=np.int32))
tm.assert_numpy_array_equal(idx.blengths, np.array([4], dtype=np.int32))
- idx = _make_index(4, np.array([0, 2, 3], dtype=np.int32), kind="block")
+ idx = make_sparse_index(4, np.array([0, 2, 3], dtype=np.int32), kind="block")
assert isinstance(idx, BlockIndex)
assert idx.npoints == 3
tm.assert_numpy_array_equal(idx.blocs, np.array([0, 2], dtype=np.int32))
@@ -428,7 +434,7 @@ class TestBlockIndex:
def test_make_block_boundary(self):
for i in [5, 10, 100, 101]:
- idx = _make_index(i, np.arange(0, i, 2, dtype=np.int32), kind="block")
+ idx = make_sparse_index(i, np.arange(0, i, 2, dtype=np.int32), kind="block")
exp = np.arange(0, i, 2, dtype=np.int32)
tm.assert_numpy_array_equal(idx.blocs, exp)
@@ -514,17 +520,19 @@ class TestIntIndex:
IntIndex(length=5, indices=[1, 3, 3])
def test_int_internal(self):
- idx = _make_index(4, np.array([2, 3], dtype=np.int32), kind="integer")
+ idx = make_sparse_index(4, np.array([2, 3], dtype=np.int32), kind="integer")
assert isinstance(idx, IntIndex)
assert idx.npoints == 2
tm.assert_numpy_array_equal(idx.indices, np.array([2, 3], dtype=np.int32))
- idx = _make_index(4, np.array([], dtype=np.int32), kind="integer")
+ idx = make_sparse_index(4, np.array([], dtype=np.int32), kind="integer")
assert isinstance(idx, IntIndex)
assert idx.npoints == 0
tm.assert_numpy_array_equal(idx.indices, np.array([], dtype=np.int32))
- idx = _make_index(4, np.array([0, 1, 2, 3], dtype=np.int32), kind="integer")
+ idx = make_sparse_index(
+ 4, np.array([0, 1, 2, 3], dtype=np.int32), kind="integer"
+ )
assert isinstance(idx, IntIndex)
assert idx.npoints == 4
tm.assert_numpy_array_equal(idx.indices, np.array([0, 1, 2, 3], dtype=np.int32))
diff --git a/pandas/tests/computation/test_compat.py b/pandas/tests/computation/test_compat.py
index ead102f53..9fc3ed480 100644
--- a/pandas/tests/computation/test_compat.py
+++ b/pandas/tests/computation/test_compat.py
@@ -5,7 +5,7 @@ import pytest
from pandas.compat._optional import VERSIONS
import pandas as pd
-from pandas.core.computation.engines import _engines
+from pandas.core.computation.engines import ENGINES
import pandas.core.computation.expr as expr
@@ -26,8 +26,8 @@ def test_compat():
pytest.skip("not testing numexpr version compat")
-@pytest.mark.parametrize("engine", _engines)
-@pytest.mark.parametrize("parser", expr._parsers)
+@pytest.mark.parametrize("engine", ENGINES)
+@pytest.mark.parametrize("parser", expr.PARSERS)
def test_invalid_numexpr_version(engine, parser):
def testit():
a, b = 1, 2 # noqa
diff --git a/pandas/tests/computation/test_eval.py b/pandas/tests/computation/test_eval.py
index 72dc04e68..cca64a6bf 100644
--- a/pandas/tests/computation/test_eval.py
+++ b/pandas/tests/computation/test_eval.py
@@ -19,7 +19,7 @@ from pandas import DataFrame, Series, compat, date_range
import pandas._testing as tm
from pandas.core.computation import pytables
from pandas.core.computation.check import NUMEXPR_VERSION
-from pandas.core.computation.engines import NumExprClobberingError, _engines
+from pandas.core.computation.engines import ENGINES, NumExprClobberingError
import pandas.core.computation.expr as expr
from pandas.core.computation.expr import (
BaseExprVisitor,
@@ -46,14 +46,14 @@ from pandas.core.computation.ops import (
f"installed->{NUMEXPR_INSTALLED}",
),
)
- for engine in _engines
+ for engine in ENGINES
)
) # noqa
def engine(request):
return request.param
-@pytest.fixture(params=expr._parsers)
+@pytest.fixture(params=expr.PARSERS)
def parser(request):
return request.param
@@ -77,7 +77,7 @@ def unary_fns_for_ne():
def engine_has_neg_frac(engine):
- return _engines[engine].has_neg_frac
+ return ENGINES[engine].has_neg_frac
def _eval_single_bin(lhs, cmp1, rhs, engine):
@@ -168,7 +168,7 @@ class TestEvalNumexprPandas:
def setup_method(self, method):
self.setup_ops()
self.setup_data()
- self.current_engines = (engine for engine in _engines if engine != self.engine)
+ self.current_engines = (engine for engine in ENGINES if engine != self.engine)
def teardown_method(self, method):
del self.lhses, self.rhses, self.scalar_rhses, self.scalar_lhses
@@ -1921,7 +1921,7 @@ _parsers: Dict[str, Type[BaseExprVisitor]] = {
}
-@pytest.mark.parametrize("engine", _engines)
+@pytest.mark.parametrize("engine", ENGINES)
@pytest.mark.parametrize("parser", _parsers)
def test_disallowed_nodes(engine, parser):
VisitorClass = _parsers[parser]