Skip to content

Commit 0aa2a54

Browse files
committed
De-privatize (pandas-dev#36130)
1 parent 28f6ca5 commit 0aa2a54

File tree

10 files changed

+48
-51
lines changed

10 files changed

+48
-51
lines changed

pandas/core/dtypes/dtypes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def _hash_categories(categories, ordered: Ordered = True) -> int:
395395
from pandas.core.dtypes.common import DT64NS_DTYPE, is_datetime64tz_dtype
396396

397397
from pandas.core.util.hashing import (
398-
_combine_hash_arrays,
398+
combine_hash_arrays,
399399
hash_array,
400400
hash_tuples,
401401
)
@@ -427,7 +427,7 @@ def _hash_categories(categories, ordered: Ordered = True) -> int:
427427
)
428428
else:
429429
cat_array = [cat_array]
430-
hashed = _combine_hash_arrays(iter(cat_array), num_items=len(cat_array))
430+
hashed = combine_hash_arrays(iter(cat_array), num_items=len(cat_array))
431431
return np.bitwise_xor.reduce(hashed)
432432

433433
@classmethod

pandas/core/indexes/datetimes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,9 @@ def _mpl_repr(self):
354354

355355
@property
356356
def _formatter_func(self):
357-
from pandas.io.formats.format import _get_format_datetime64
357+
from pandas.io.formats.format import get_format_datetime64
358358

359-
formatter = _get_format_datetime64(is_dates_only=self._is_dates_only)
359+
formatter = get_format_datetime64(is_dates_only=self._is_dates_only)
360360
return lambda x: f"'{formatter(x, tz=self.tz)}'"
361361

362362
# --------------------------------------------------------------------

pandas/core/indexing.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2291,7 +2291,7 @@ def need_slice(obj) -> bool:
22912291
)
22922292

22932293

2294-
def _non_reducing_slice(slice_):
2294+
def non_reducing_slice(slice_):
22952295
"""
22962296
Ensure that a slice doesn't reduce to a Series or Scalar.
22972297
@@ -2330,7 +2330,7 @@ def pred(part) -> bool:
23302330
return tuple(slice_)
23312331

23322332

2333-
def _maybe_numeric_slice(df, slice_, include_bool=False):
2333+
def maybe_numeric_slice(df, slice_, include_bool: bool = False):
23342334
"""
23352335
Want nice defaults for background_gradient that don't break
23362336
with non-numeric data. But if slice_ is passed go with that.

pandas/core/util/hashing.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
_default_hash_key = "0123456789123456"
2525

2626

27-
def _combine_hash_arrays(arrays, num_items: int):
27+
def combine_hash_arrays(arrays, num_items: int):
2828
"""
2929
Parameters
3030
----------
@@ -108,7 +108,7 @@ def hash_pandas_object(
108108
for _ in [None]
109109
)
110110
arrays = itertools.chain([h], index_iter)
111-
h = _combine_hash_arrays(arrays, 2)
111+
h = combine_hash_arrays(arrays, 2)
112112

113113
h = Series(h, index=obj.index, dtype="uint64", copy=False)
114114

@@ -131,7 +131,7 @@ def hash_pandas_object(
131131
# keep `hashes` specifically a generator to keep mypy happy
132132
_hashes = itertools.chain(hashes, index_hash_generator)
133133
hashes = (x for x in _hashes)
134-
h = _combine_hash_arrays(hashes, num_items)
134+
h = combine_hash_arrays(hashes, num_items)
135135

136136
h = Series(h, index=obj.index, dtype="uint64", copy=False)
137137
else:
@@ -175,7 +175,7 @@ def hash_tuples(vals, encoding="utf8", hash_key: str = _default_hash_key):
175175
hashes = (
176176
_hash_categorical(cat, encoding=encoding, hash_key=hash_key) for cat in vals
177177
)
178-
h = _combine_hash_arrays(hashes, len(vals))
178+
h = combine_hash_arrays(hashes, len(vals))
179179
if is_tuple:
180180
h = h[0]
181181

pandas/io/formats/format.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1624,7 +1624,7 @@ def _format_datetime64_dateonly(
16241624
return x._date_repr
16251625

16261626

1627-
def _get_format_datetime64(
1627+
def get_format_datetime64(
16281628
is_dates_only: bool, nat_rep: str = "NaT", date_format: None = None
16291629
) -> Callable:
16301630

@@ -1656,7 +1656,7 @@ def _format_strings(self) -> List[str]:
16561656
""" we by definition have a TZ """
16571657
values = self.values.astype(object)
16581658
is_dates_only = _is_dates_only(values)
1659-
formatter = self.formatter or _get_format_datetime64(
1659+
formatter = self.formatter or get_format_datetime64(
16601660
is_dates_only, date_format=self.date_format
16611661
)
16621662
fmt_values = [formatter(x) for x in values]

pandas/io/formats/style.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import pandas.core.common as com
3737
from pandas.core.frame import DataFrame
3838
from pandas.core.generic import NDFrame
39-
from pandas.core.indexing import _maybe_numeric_slice, _non_reducing_slice
39+
from pandas.core.indexing import maybe_numeric_slice, non_reducing_slice
4040

4141
jinja2 = import_optional_dependency("jinja2", extra="DataFrame.style requires jinja2.")
4242

@@ -475,7 +475,7 @@ def format(self, formatter, subset=None, na_rep: Optional[str] = None) -> "Style
475475
row_locs = range(len(self.data))
476476
col_locs = range(len(self.data.columns))
477477
else:
478-
subset = _non_reducing_slice(subset)
478+
subset = non_reducing_slice(subset)
479479
if len(subset) == 1:
480480
subset = subset, self.data.columns
481481

@@ -633,7 +633,7 @@ def _apply(
633633
**kwargs,
634634
) -> "Styler":
635635
subset = slice(None) if subset is None else subset
636-
subset = _non_reducing_slice(subset)
636+
subset = non_reducing_slice(subset)
637637
data = self.data.loc[subset]
638638
if axis is not None:
639639
result = data.apply(func, axis=axis, result_type="expand", **kwargs)
@@ -725,7 +725,7 @@ def _applymap(self, func: Callable, subset=None, **kwargs) -> "Styler":
725725
func = partial(func, **kwargs) # applymap doesn't take kwargs?
726726
if subset is None:
727727
subset = pd.IndexSlice[:]
728-
subset = _non_reducing_slice(subset)
728+
subset = non_reducing_slice(subset)
729729
result = self.data.loc[subset].applymap(func)
730730
self._update_ctx(result)
731731
return self
@@ -985,7 +985,7 @@ def hide_columns(self, subset) -> "Styler":
985985
-------
986986
self : Styler
987987
"""
988-
subset = _non_reducing_slice(subset)
988+
subset = non_reducing_slice(subset)
989989
hidden_df = self.data.loc[subset]
990990
self.hidden_columns = self.columns.get_indexer_for(hidden_df.columns)
991991
return self
@@ -1087,8 +1087,8 @@ def background_gradient(
10871087
of the data is extended by ``low * (x.max() - x.min())`` and ``high *
10881088
(x.max() - x.min())`` before normalizing.
10891089
"""
1090-
subset = _maybe_numeric_slice(self.data, subset)
1091-
subset = _non_reducing_slice(subset)
1090+
subset = maybe_numeric_slice(self.data, subset)
1091+
subset = non_reducing_slice(subset)
10921092
self.apply(
10931093
self._background_gradient,
10941094
cmap=cmap,
@@ -1322,8 +1322,8 @@ def bar(
13221322
"(eg: color=['#d65f5f', '#5fba7d'])"
13231323
)
13241324

1325-
subset = _maybe_numeric_slice(self.data, subset)
1326-
subset = _non_reducing_slice(subset)
1325+
subset = maybe_numeric_slice(self.data, subset)
1326+
subset = non_reducing_slice(subset)
13271327
self.apply(
13281328
self._bar,
13291329
subset=subset,
@@ -1390,7 +1390,7 @@ def _highlight_handler(
13901390
axis: Optional[Axis] = None,
13911391
max_: bool = True,
13921392
) -> "Styler":
1393-
subset = _non_reducing_slice(_maybe_numeric_slice(self.data, subset))
1393+
subset = non_reducing_slice(maybe_numeric_slice(self.data, subset))
13941394
self.apply(
13951395
self._highlight_extrema, color=color, axis=axis, subset=subset, max_=max_
13961396
)

pandas/plotting/_matplotlib/core.py

+13-16
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333
from pandas.plotting._matplotlib.compat import _mpl_ge_3_0_0
3434
from pandas.plotting._matplotlib.converter import register_pandas_matplotlib_converters
3535
from pandas.plotting._matplotlib.style import get_standard_colors
36+
from pandas.plotting._matplotlib.timeseries import (
37+
decorate_axes,
38+
format_dateaxis,
39+
maybe_convert_index,
40+
maybe_resample,
41+
use_dynamic_x,
42+
)
3643
from pandas.plotting._matplotlib.tools import (
3744
create_subplots,
3845
flatten_axes,
@@ -1074,15 +1081,11 @@ def _is_ts_plot(self) -> bool:
10741081
return not self.x_compat and self.use_index and self._use_dynamic_x()
10751082

10761083
def _use_dynamic_x(self):
1077-
from pandas.plotting._matplotlib.timeseries import _use_dynamic_x
1078-
1079-
return _use_dynamic_x(self._get_ax(0), self.data)
1084+
return use_dynamic_x(self._get_ax(0), self.data)
10801085

10811086
def _make_plot(self):
10821087
if self._is_ts_plot():
1083-
from pandas.plotting._matplotlib.timeseries import _maybe_convert_index
1084-
1085-
data = _maybe_convert_index(self._get_ax(0), self.data)
1088+
data = maybe_convert_index(self._get_ax(0), self.data)
10861089

10871090
x = data.index # dummy, not used
10881091
plotf = self._ts_plot
@@ -1142,24 +1145,18 @@ def _plot(
11421145

11431146
@classmethod
11441147
def _ts_plot(cls, ax: "Axes", x, data, style=None, **kwds):
1145-
from pandas.plotting._matplotlib.timeseries import (
1146-
_decorate_axes,
1147-
_maybe_resample,
1148-
format_dateaxis,
1149-
)
1150-
11511148
# accept x to be consistent with normal plot func,
11521149
# x is not passed to tsplot as it uses data.index as x coordinate
11531150
# column_num must be in kwds for stacking purpose
1154-
freq, data = _maybe_resample(data, ax, kwds)
1151+
freq, data = maybe_resample(data, ax, kwds)
11551152

11561153
# Set ax with freq info
1157-
_decorate_axes(ax, freq, kwds)
1154+
decorate_axes(ax, freq, kwds)
11581155
# digging deeper
11591156
if hasattr(ax, "left_ax"):
1160-
_decorate_axes(ax.left_ax, freq, kwds)
1157+
decorate_axes(ax.left_ax, freq, kwds)
11611158
if hasattr(ax, "right_ax"):
1162-
_decorate_axes(ax.right_ax, freq, kwds)
1159+
decorate_axes(ax.right_ax, freq, kwds)
11631160
ax._plot_data.append((data, cls._kind, kwds))
11641161

11651162
lines = cls._plot(ax, data.index, data.values, style=style, **kwds)

pandas/plotting/_matplotlib/timeseries.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
# Plotting functions and monkey patches
3333

3434

35-
def _maybe_resample(series: "Series", ax: "Axes", kwargs):
35+
def maybe_resample(series: "Series", ax: "Axes", kwargs):
3636
# resample against axes freq if necessary
3737
freq, ax_freq = _get_freq(ax, series)
3838

@@ -105,7 +105,7 @@ def _replot_ax(ax: "Axes", freq, kwargs):
105105
ax._plot_data = []
106106
ax.clear()
107107

108-
_decorate_axes(ax, freq, kwargs)
108+
decorate_axes(ax, freq, kwargs)
109109

110110
lines = []
111111
labels = []
@@ -128,7 +128,7 @@ def _replot_ax(ax: "Axes", freq, kwargs):
128128
return lines, labels
129129

130130

131-
def _decorate_axes(ax: "Axes", freq, kwargs):
131+
def decorate_axes(ax: "Axes", freq, kwargs):
132132
"""Initialize axes for time-series plotting"""
133133
if not hasattr(ax, "_plot_data"):
134134
ax._plot_data = []
@@ -193,7 +193,7 @@ def _get_freq(ax: "Axes", series: "Series"):
193193
return freq, ax_freq
194194

195195

196-
def _use_dynamic_x(ax: "Axes", data: FrameOrSeriesUnion) -> bool:
196+
def use_dynamic_x(ax: "Axes", data: FrameOrSeriesUnion) -> bool:
197197
freq = _get_index_freq(data.index)
198198
ax_freq = _get_ax_freq(ax)
199199

@@ -235,7 +235,7 @@ def _get_index_freq(index: "Index") -> Optional[BaseOffset]:
235235
return freq
236236

237237

238-
def _maybe_convert_index(ax: "Axes", data):
238+
def maybe_convert_index(ax: "Axes", data):
239239
# tsplot converts automatically, but don't want to convert index
240240
# over and over for DataFrames
241241
if isinstance(data.index, (ABCDatetimeIndex, ABCPeriodIndex)):

pandas/tests/indexing/multiindex/test_slice.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pandas as pd
77
from pandas import DataFrame, Index, MultiIndex, Series, Timestamp
88
import pandas._testing as tm
9-
from pandas.core.indexing import _non_reducing_slice
9+
from pandas.core.indexing import non_reducing_slice
1010
from pandas.tests.indexing.common import _mklbl
1111

1212

@@ -739,7 +739,7 @@ def test_non_reducing_slice_on_multiindex(self):
739739
df = pd.DataFrame(dic, index=[0, 1])
740740
idx = pd.IndexSlice
741741
slice_ = idx[:, idx["b", "d"]]
742-
tslice_ = _non_reducing_slice(slice_)
742+
tslice_ = non_reducing_slice(slice_)
743743

744744
result = df.loc[tslice_]
745745
expected = pd.DataFrame({("b", "d"): [4, 1]})

pandas/tests/indexing/test_indexing.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import pandas as pd
1313
from pandas import DataFrame, Index, NaT, Series
1414
import pandas._testing as tm
15-
from pandas.core.indexing import _maybe_numeric_slice, _non_reducing_slice
15+
from pandas.core.indexing import maybe_numeric_slice, non_reducing_slice
1616
from pandas.tests.indexing.common import _mklbl
1717

1818
# ------------------------------------------------------------------------
@@ -822,7 +822,7 @@ def test_range_in_series_indexing(self, size):
822822
def test_non_reducing_slice(self, slc):
823823
df = DataFrame([[0, 1], [2, 3]])
824824

825-
tslice_ = _non_reducing_slice(slc)
825+
tslice_ = non_reducing_slice(slc)
826826
assert isinstance(df.loc[tslice_], DataFrame)
827827

828828
def test_list_slice(self):
@@ -831,18 +831,18 @@ def test_list_slice(self):
831831
df = DataFrame({"A": [1, 2], "B": [3, 4]}, index=["A", "B"])
832832
expected = pd.IndexSlice[:, ["A"]]
833833
for subset in slices:
834-
result = _non_reducing_slice(subset)
834+
result = non_reducing_slice(subset)
835835
tm.assert_frame_equal(df.loc[result], df.loc[expected])
836836

837837
def test_maybe_numeric_slice(self):
838838
df = DataFrame({"A": [1, 2], "B": ["c", "d"], "C": [True, False]})
839-
result = _maybe_numeric_slice(df, slice_=None)
839+
result = maybe_numeric_slice(df, slice_=None)
840840
expected = pd.IndexSlice[:, ["A"]]
841841
assert result == expected
842842

843-
result = _maybe_numeric_slice(df, None, include_bool=True)
843+
result = maybe_numeric_slice(df, None, include_bool=True)
844844
expected = pd.IndexSlice[:, ["A", "C"]]
845-
result = _maybe_numeric_slice(df, [1])
845+
result = maybe_numeric_slice(df, [1])
846846
expected = [1]
847847
assert result == expected
848848

0 commit comments

Comments
 (0)