Skip to content

Commit bc0e507

Browse files
authored
De-privatize (#36107)
1 parent fadb72c commit bc0e507

File tree

24 files changed

+81
-83
lines changed

24 files changed

+81
-83
lines changed

pandas/_libs/indexing.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cdef class _NDFrameIndexerBase:
1+
cdef class NDFrameIndexerBase:
22
"""
33
A base class for _NDFrameIndexer for fast instantiation and attribute access.
44
"""

pandas/_libs/tslibs/parsing.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ class _timelex:
771771
_DATEUTIL_LEXER_SPLIT = _timelex.split
772772

773773

774-
def _format_is_iso(f) -> bint:
774+
def format_is_iso(f: str) -> bint:
775775
"""
776776
Does format match the iso8601 set that can be handled by the C parser?
777777
Generally of form YYYY-MM-DDTHH:MM:SS - date separator can be different
@@ -789,7 +789,7 @@ def _format_is_iso(f) -> bint:
789789
return False
790790

791791

792-
def _guess_datetime_format(
792+
def guess_datetime_format(
793793
dt_str,
794794
bint dayfirst=False,
795795
dt_str_parse=du_parse,

pandas/core/arrays/datetimes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -602,9 +602,9 @@ def astype(self, dtype, copy=True):
602602
# Rendering Methods
603603

604604
def _format_native_types(self, na_rep="NaT", date_format=None, **kwargs):
605-
from pandas.io.formats.format import _get_format_datetime64_from_values
605+
from pandas.io.formats.format import get_format_datetime64_from_values
606606

607-
fmt = _get_format_datetime64_from_values(self, date_format)
607+
fmt = get_format_datetime64_from_values(self, date_format)
608608

609609
return tslib.format_array_from_datetime(
610610
self.asi8.ravel(), tz=self.tz, format=fmt, na_rep=na_rep

pandas/core/arrays/timedeltas.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -379,14 +379,14 @@ def median(
379379
# Rendering Methods
380380

381381
def _formatter(self, boxed=False):
382-
from pandas.io.formats.format import _get_format_timedelta64
382+
from pandas.io.formats.format import get_format_timedelta64
383383

384-
return _get_format_timedelta64(self, box=True)
384+
return get_format_timedelta64(self, box=True)
385385

386386
def _format_native_types(self, na_rep="NaT", date_format=None, **kwargs):
387-
from pandas.io.formats.format import _get_format_timedelta64
387+
from pandas.io.formats.format import get_format_timedelta64
388388

389-
formatter = _get_format_timedelta64(self._data, na_rep)
389+
formatter = get_format_timedelta64(self._data, na_rep)
390390
return np.array([formatter(x) for x in self._data.ravel()]).reshape(self.shape)
391391

392392
# ----------------------------------------------------------------

pandas/core/common.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
ABCIndexClass,
3232
ABCSeries,
3333
)
34-
from pandas.core.dtypes.inference import _iterable_not_string
34+
from pandas.core.dtypes.inference import iterable_not_string
3535
from pandas.core.dtypes.missing import isna, isnull, notnull # noqa
3636

3737

@@ -61,7 +61,7 @@ def flatten(l):
6161
flattened : generator
6262
"""
6363
for el in l:
64-
if _iterable_not_string(el):
64+
if iterable_not_string(el):
6565
for s in flatten(el):
6666
yield s
6767
else:

pandas/core/computation/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from pandas._config import get_option
66

77

8-
def _ensure_decoded(s):
8+
def ensure_decoded(s):
99
"""
1010
If we have bytes, decode them to unicode.
1111
"""

pandas/core/computation/ops.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from pandas.core.dtypes.common import is_list_like, is_scalar
1616

1717
import pandas.core.common as com
18-
from pandas.core.computation.common import _ensure_decoded, result_type_many
18+
from pandas.core.computation.common import ensure_decoded, result_type_many
1919
from pandas.core.computation.scope import _DEFAULT_GLOBALS
2020

2121
from pandas.io.formats.printing import pprint_thing, pprint_thing_encoded
@@ -466,7 +466,7 @@ def stringify(value):
466466
v = rhs.value
467467
if isinstance(v, (int, float)):
468468
v = stringify(v)
469-
v = Timestamp(_ensure_decoded(v))
469+
v = Timestamp(ensure_decoded(v))
470470
if v.tz is not None:
471471
v = v.tz_convert("UTC")
472472
self.rhs.update(v)
@@ -475,7 +475,7 @@ def stringify(value):
475475
v = lhs.value
476476
if isinstance(v, (int, float)):
477477
v = stringify(v)
478-
v = Timestamp(_ensure_decoded(v))
478+
v = Timestamp(ensure_decoded(v))
479479
if v.tz is not None:
480480
v = v.tz_convert("UTC")
481481
self.lhs.update(v)

pandas/core/computation/pytables.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import pandas as pd
1515
import pandas.core.common as com
1616
from pandas.core.computation import expr, ops, scope as _scope
17-
from pandas.core.computation.common import _ensure_decoded
17+
from pandas.core.computation.common import ensure_decoded
1818
from pandas.core.computation.expr import BaseExprVisitor
1919
from pandas.core.computation.ops import UndefinedVariableError, is_term
2020
from pandas.core.construction import extract_array
@@ -189,12 +189,12 @@ def stringify(value):
189189
encoder = pprint_thing
190190
return encoder(value)
191191

192-
kind = _ensure_decoded(self.kind)
193-
meta = _ensure_decoded(self.meta)
192+
kind = ensure_decoded(self.kind)
193+
meta = ensure_decoded(self.meta)
194194
if kind == "datetime64" or kind == "datetime":
195195
if isinstance(v, (int, float)):
196196
v = stringify(v)
197-
v = _ensure_decoded(v)
197+
v = ensure_decoded(v)
198198
v = Timestamp(v)
199199
if v.tz is not None:
200200
v = v.tz_convert("UTC")

pandas/core/dtypes/common.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -635,8 +635,8 @@ def is_dtype_equal(source, target) -> bool:
635635
False
636636
"""
637637
try:
638-
source = _get_dtype(source)
639-
target = _get_dtype(target)
638+
source = get_dtype(source)
639+
target = get_dtype(target)
640640
return source == target
641641
except (TypeError, AttributeError):
642642

@@ -984,10 +984,10 @@ def is_datetime64_ns_dtype(arr_or_dtype) -> bool:
984984
if arr_or_dtype is None:
985985
return False
986986
try:
987-
tipo = _get_dtype(arr_or_dtype)
987+
tipo = get_dtype(arr_or_dtype)
988988
except TypeError:
989989
if is_datetime64tz_dtype(arr_or_dtype):
990-
tipo = _get_dtype(arr_or_dtype.dtype)
990+
tipo = get_dtype(arr_or_dtype.dtype)
991991
else:
992992
return False
993993
return tipo == DT64NS_DTYPE or getattr(tipo, "base", None) == DT64NS_DTYPE
@@ -1372,7 +1372,7 @@ def is_bool_dtype(arr_or_dtype) -> bool:
13721372
if arr_or_dtype is None:
13731373
return False
13741374
try:
1375-
dtype = _get_dtype(arr_or_dtype)
1375+
dtype = get_dtype(arr_or_dtype)
13761376
except TypeError:
13771377
return False
13781378

@@ -1557,13 +1557,13 @@ def _is_dtype(arr_or_dtype, condition) -> bool:
15571557
if arr_or_dtype is None:
15581558
return False
15591559
try:
1560-
dtype = _get_dtype(arr_or_dtype)
1560+
dtype = get_dtype(arr_or_dtype)
15611561
except (TypeError, ValueError, UnicodeEncodeError):
15621562
return False
15631563
return condition(dtype)
15641564

15651565

1566-
def _get_dtype(arr_or_dtype) -> DtypeObj:
1566+
def get_dtype(arr_or_dtype) -> DtypeObj:
15671567
"""
15681568
Get the dtype instance associated with an array
15691569
or dtype object.
@@ -1694,7 +1694,7 @@ def infer_dtype_from_object(dtype):
16941694
try:
16951695
return infer_dtype_from_object(getattr(np, dtype))
16961696
except (AttributeError, TypeError):
1697-
# Handles cases like _get_dtype(int) i.e.,
1697+
# Handles cases like get_dtype(int) i.e.,
16981698
# Python objects that are valid dtypes
16991699
# (unlike user-defined types, in general)
17001700
#

pandas/core/dtypes/inference.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def is_number(obj) -> bool:
6868
return isinstance(obj, (Number, np.number))
6969

7070

71-
def _iterable_not_string(obj) -> bool:
71+
def iterable_not_string(obj) -> bool:
7272
"""
7373
Check if the object is an iterable but not a string.
7474
@@ -83,11 +83,11 @@ def _iterable_not_string(obj) -> bool:
8383
8484
Examples
8585
--------
86-
>>> _iterable_not_string([1, 2, 3])
86+
>>> iterable_not_string([1, 2, 3])
8787
True
88-
>>> _iterable_not_string("foo")
88+
>>> iterable_not_string("foo")
8989
False
90-
>>> _iterable_not_string(1)
90+
>>> iterable_not_string(1)
9191
False
9292
"""
9393
return isinstance(obj, abc.Iterable) and not isinstance(obj, str)

pandas/core/dtypes/missing.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def notna(obj):
338338
notnull = notna
339339

340340

341-
def _isna_compat(arr, fill_value=np.nan) -> bool:
341+
def isna_compat(arr, fill_value=np.nan) -> bool:
342342
"""
343343
Parameters
344344
----------
@@ -496,7 +496,7 @@ def array_equals(left: ArrayLike, right: ArrayLike) -> bool:
496496
return array_equivalent(left, right, dtype_equal=True)
497497

498498

499-
def _infer_fill_value(val):
499+
def infer_fill_value(val):
500500
"""
501501
infer the fill value for the nan/NaT from the provided
502502
scalar/ndarray/list-like if we are a NaT, return the correct dtyped
@@ -516,11 +516,11 @@ def _infer_fill_value(val):
516516
return np.nan
517517

518518

519-
def _maybe_fill(arr, fill_value=np.nan):
519+
def maybe_fill(arr, fill_value=np.nan):
520520
"""
521521
if we have a compatible fill_value and arr dtype, then fill
522522
"""
523-
if _isna_compat(arr, fill_value):
523+
if isna_compat(arr, fill_value):
524524
arr.fill(fill_value)
525525
return arr
526526

pandas/core/groupby/ops.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
is_timedelta64_dtype,
3838
needs_i8_conversion,
3939
)
40-
from pandas.core.dtypes.missing import _maybe_fill, isna
40+
from pandas.core.dtypes.missing import isna, maybe_fill
4141

4242
import pandas.core.algorithms as algorithms
4343
from pandas.core.base import SelectionMixin
@@ -524,13 +524,11 @@ def _cython_operation(
524524
codes, _, _ = self.group_info
525525

526526
if kind == "aggregate":
527-
result = _maybe_fill(
528-
np.empty(out_shape, dtype=out_dtype), fill_value=np.nan
529-
)
527+
result = maybe_fill(np.empty(out_shape, dtype=out_dtype), fill_value=np.nan)
530528
counts = np.zeros(self.ngroups, dtype=np.int64)
531529
result = self._aggregate(result, counts, values, codes, func, min_count)
532530
elif kind == "transform":
533-
result = _maybe_fill(
531+
result = maybe_fill(
534532
np.empty_like(values, dtype=out_dtype), fill_value=np.nan
535533
)
536534

pandas/core/indexes/timedeltas.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ def _simple_new(cls, values: TimedeltaArray, name: Label = None):
177177

178178
@property
179179
def _formatter_func(self):
180-
from pandas.io.formats.format import _get_format_timedelta64
180+
from pandas.io.formats.format import get_format_timedelta64
181181

182-
return _get_format_timedelta64(self, box=True)
182+
return get_format_timedelta64(self, box=True)
183183

184184
# -------------------------------------------------------------------
185185

pandas/core/indexing.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from pandas._config.config import option_context
66

7-
from pandas._libs.indexing import _NDFrameIndexerBase
7+
from pandas._libs.indexing import NDFrameIndexerBase
88
from pandas._libs.lib import item_from_zerodim
99
from pandas.errors import AbstractMethodError, InvalidIndexError
1010
from pandas.util._decorators import doc
@@ -22,7 +22,7 @@
2222
)
2323
from pandas.core.dtypes.concat import concat_compat
2424
from pandas.core.dtypes.generic import ABCDataFrame, ABCMultiIndex, ABCSeries
25-
from pandas.core.dtypes.missing import _infer_fill_value, isna
25+
from pandas.core.dtypes.missing import infer_fill_value, isna
2626

2727
import pandas.core.common as com
2828
from pandas.core.construction import array as pd_array
@@ -583,7 +583,7 @@ def iat(self) -> "_iAtIndexer":
583583
return _iAtIndexer("iat", self)
584584

585585

586-
class _LocationIndexer(_NDFrameIndexerBase):
586+
class _LocationIndexer(NDFrameIndexerBase):
587587
_valid_types: str
588588
axis = None
589589

@@ -1604,7 +1604,7 @@ def _setitem_with_indexer(self, indexer, value):
16041604
return
16051605

16061606
# add a new item with the dtype setup
1607-
self.obj[key] = _infer_fill_value(value)
1607+
self.obj[key] = infer_fill_value(value)
16081608

16091609
new_indexer = convert_from_missing_indexer_tuple(
16101610
indexer, self.obj.axes
@@ -2017,7 +2017,7 @@ def _align_frame(self, indexer, df: ABCDataFrame):
20172017
raise ValueError("Incompatible indexer with DataFrame")
20182018

20192019

2020-
class _ScalarAccessIndexer(_NDFrameIndexerBase):
2020+
class _ScalarAccessIndexer(NDFrameIndexerBase):
20212021
"""
20222022
Access scalars quickly.
20232023
"""

pandas/core/internals/blocks.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
ABCPandasArray,
5757
ABCSeries,
5858
)
59-
from pandas.core.dtypes.missing import _isna_compat, is_valid_nat_for_dtype, isna
59+
from pandas.core.dtypes.missing import is_valid_nat_for_dtype, isna, isna_compat
6060

6161
import pandas.core.algorithms as algos
6262
from pandas.core.array_algos.transforms import shift
@@ -487,7 +487,7 @@ def _maybe_downcast(self, blocks: List["Block"], downcast=None) -> List["Block"]
487487
):
488488
return blocks
489489

490-
return _extend_blocks([b.downcast(downcast) for b in blocks])
490+
return extend_blocks([b.downcast(downcast) for b in blocks])
491491

492492
def downcast(self, dtypes=None):
493493
""" try to downcast each item to the dict of dtypes if present """
@@ -2474,7 +2474,7 @@ def _maybe_downcast(self, blocks: List["Block"], downcast=None) -> List["Block"]
24742474
return blocks
24752475

24762476
# split and convert the blocks
2477-
return _extend_blocks([b.convert(datetime=True, numeric=False) for b in blocks])
2477+
return extend_blocks([b.convert(datetime=True, numeric=False) for b in blocks])
24782478

24792479
def _can_hold_element(self, element: Any) -> bool:
24802480
return True
@@ -2503,7 +2503,7 @@ def replace(self, to_replace, value, inplace=False, regex=False, convert=True):
25032503
result = b._replace_single(
25042504
to_rep, v, inplace=inplace, regex=regex, convert=convert
25052505
)
2506-
result_blocks = _extend_blocks(result, result_blocks)
2506+
result_blocks = extend_blocks(result, result_blocks)
25072507
blocks = result_blocks
25082508
return result_blocks
25092509

@@ -2514,7 +2514,7 @@ def replace(self, to_replace, value, inplace=False, regex=False, convert=True):
25142514
result = b._replace_single(
25152515
to_rep, value, inplace=inplace, regex=regex, convert=convert
25162516
)
2517-
result_blocks = _extend_blocks(result, result_blocks)
2517+
result_blocks = extend_blocks(result, result_blocks)
25182518
blocks = result_blocks
25192519
return result_blocks
25202520

@@ -2769,7 +2769,7 @@ def make_block(values, placement, klass=None, ndim=None, dtype=None):
27692769
# -----------------------------------------------------------------
27702770

27712771

2772-
def _extend_blocks(result, blocks=None):
2772+
def extend_blocks(result, blocks=None):
27732773
""" return a new extended blocks, given the result """
27742774
if blocks is None:
27752775
blocks = []
@@ -2860,7 +2860,7 @@ def _putmask_smart(v: np.ndarray, mask: np.ndarray, n) -> np.ndarray:
28602860
else:
28612861
# make sure that we have a nullable type
28622862
# if we have nulls
2863-
if not _isna_compat(v, nn[0]):
2863+
if not isna_compat(v, nn[0]):
28642864
pass
28652865
elif not (is_float_dtype(nn.dtype) or is_integer_dtype(nn.dtype)):
28662866
# only compare integers/floats

0 commit comments

Comments
 (0)