Skip to content

CLN: De-privatize #36130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def _hash_categories(categories, ordered: Ordered = True) -> int:
from pandas.core.dtypes.common import DT64NS_DTYPE, is_datetime64tz_dtype

from pandas.core.util.hashing import (
_combine_hash_arrays,
combine_hash_arrays,
hash_array,
hash_tuples,
)
Expand Down Expand Up @@ -427,7 +427,7 @@ def _hash_categories(categories, ordered: Ordered = True) -> int:
)
else:
cat_array = [cat_array]
hashed = _combine_hash_arrays(iter(cat_array), num_items=len(cat_array))
hashed = combine_hash_arrays(iter(cat_array), num_items=len(cat_array))
return np.bitwise_xor.reduce(hashed)

@classmethod
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,9 @@ def _mpl_repr(self):

@property
def _formatter_func(self):
from pandas.io.formats.format import _get_format_datetime64
from pandas.io.formats.format import get_format_datetime64

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

# --------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2291,7 +2291,7 @@ def need_slice(obj) -> bool:
)


def _non_reducing_slice(slice_):
def non_reducing_slice(slice_):
"""
Ensure that a slice doesn't reduce to a Series or Scalar.

Expand Down Expand Up @@ -2330,7 +2330,7 @@ def pred(part) -> bool:
return tuple(slice_)


def _maybe_numeric_slice(df, slice_, include_bool=False):
def maybe_numeric_slice(df, slice_, include_bool: bool = False):
"""
Want nice defaults for background_gradient that don't break
with non-numeric data. But if slice_ is passed go with that.
Expand Down
8 changes: 4 additions & 4 deletions pandas/core/util/hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
_default_hash_key = "0123456789123456"


def _combine_hash_arrays(arrays, num_items: int):
def combine_hash_arrays(arrays, num_items: int):
"""
Parameters
----------
Expand Down Expand Up @@ -108,7 +108,7 @@ def hash_pandas_object(
for _ in [None]
)
arrays = itertools.chain([h], index_iter)
h = _combine_hash_arrays(arrays, 2)
h = combine_hash_arrays(arrays, 2)

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

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

h = Series(h, index=obj.index, dtype="uint64", copy=False)
else:
Expand Down Expand Up @@ -175,7 +175,7 @@ def hash_tuples(vals, encoding="utf8", hash_key: str = _default_hash_key):
hashes = (
_hash_categorical(cat, encoding=encoding, hash_key=hash_key) for cat in vals
)
h = _combine_hash_arrays(hashes, len(vals))
h = combine_hash_arrays(hashes, len(vals))
if is_tuple:
h = h[0]

Expand Down
4 changes: 2 additions & 2 deletions pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -1624,7 +1624,7 @@ def _format_datetime64_dateonly(
return x._date_repr


def _get_format_datetime64(
def get_format_datetime64(
is_dates_only: bool, nat_rep: str = "NaT", date_format: None = None
) -> Callable:

Expand Down Expand Up @@ -1656,7 +1656,7 @@ def _format_strings(self) -> List[str]:
""" we by definition have a TZ """
values = self.values.astype(object)
is_dates_only = _is_dates_only(values)
formatter = self.formatter or _get_format_datetime64(
formatter = self.formatter or get_format_datetime64(
is_dates_only, date_format=self.date_format
)
fmt_values = [formatter(x) for x in values]
Expand Down
20 changes: 10 additions & 10 deletions pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import pandas.core.common as com
from pandas.core.frame import DataFrame
from pandas.core.generic import NDFrame
from pandas.core.indexing import _maybe_numeric_slice, _non_reducing_slice
from pandas.core.indexing import maybe_numeric_slice, non_reducing_slice

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

Expand Down Expand Up @@ -475,7 +475,7 @@ def format(self, formatter, subset=None, na_rep: Optional[str] = None) -> "Style
row_locs = range(len(self.data))
col_locs = range(len(self.data.columns))
else:
subset = _non_reducing_slice(subset)
subset = non_reducing_slice(subset)
if len(subset) == 1:
subset = subset, self.data.columns

Expand Down Expand Up @@ -633,7 +633,7 @@ def _apply(
**kwargs,
) -> "Styler":
subset = slice(None) if subset is None else subset
subset = _non_reducing_slice(subset)
subset = non_reducing_slice(subset)
data = self.data.loc[subset]
if axis is not None:
result = data.apply(func, axis=axis, result_type="expand", **kwargs)
Expand Down Expand Up @@ -725,7 +725,7 @@ def _applymap(self, func: Callable, subset=None, **kwargs) -> "Styler":
func = partial(func, **kwargs) # applymap doesn't take kwargs?
if subset is None:
subset = pd.IndexSlice[:]
subset = _non_reducing_slice(subset)
subset = non_reducing_slice(subset)
result = self.data.loc[subset].applymap(func)
self._update_ctx(result)
return self
Expand Down Expand Up @@ -985,7 +985,7 @@ def hide_columns(self, subset) -> "Styler":
-------
self : Styler
"""
subset = _non_reducing_slice(subset)
subset = non_reducing_slice(subset)
hidden_df = self.data.loc[subset]
self.hidden_columns = self.columns.get_indexer_for(hidden_df.columns)
return self
Expand Down Expand Up @@ -1087,8 +1087,8 @@ def background_gradient(
of the data is extended by ``low * (x.max() - x.min())`` and ``high *
(x.max() - x.min())`` before normalizing.
"""
subset = _maybe_numeric_slice(self.data, subset)
subset = _non_reducing_slice(subset)
subset = maybe_numeric_slice(self.data, subset)
subset = non_reducing_slice(subset)
self.apply(
self._background_gradient,
cmap=cmap,
Expand Down Expand Up @@ -1322,8 +1322,8 @@ def bar(
"(eg: color=['#d65f5f', '#5fba7d'])"
)

subset = _maybe_numeric_slice(self.data, subset)
subset = _non_reducing_slice(subset)
subset = maybe_numeric_slice(self.data, subset)
subset = non_reducing_slice(subset)
self.apply(
self._bar,
subset=subset,
Expand Down Expand Up @@ -1390,7 +1390,7 @@ def _highlight_handler(
axis: Optional[Axis] = None,
max_: bool = True,
) -> "Styler":
subset = _non_reducing_slice(_maybe_numeric_slice(self.data, subset))
subset = non_reducing_slice(maybe_numeric_slice(self.data, subset))
self.apply(
self._highlight_extrema, color=color, axis=axis, subset=subset, max_=max_
)
Expand Down
29 changes: 13 additions & 16 deletions pandas/plotting/_matplotlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
from pandas.plotting._matplotlib.compat import _mpl_ge_3_0_0
from pandas.plotting._matplotlib.converter import register_pandas_matplotlib_converters
from pandas.plotting._matplotlib.style import get_standard_colors
from pandas.plotting._matplotlib.timeseries import (
decorate_axes,
format_dateaxis,
maybe_convert_index,
maybe_resample,
use_dynamic_x,
)
from pandas.plotting._matplotlib.tools import (
create_subplots,
flatten_axes,
Expand Down Expand Up @@ -1074,15 +1081,11 @@ def _is_ts_plot(self) -> bool:
return not self.x_compat and self.use_index and self._use_dynamic_x()

def _use_dynamic_x(self):
from pandas.plotting._matplotlib.timeseries import _use_dynamic_x

return _use_dynamic_x(self._get_ax(0), self.data)
return use_dynamic_x(self._get_ax(0), self.data)

def _make_plot(self):
if self._is_ts_plot():
from pandas.plotting._matplotlib.timeseries import _maybe_convert_index

data = _maybe_convert_index(self._get_ax(0), self.data)
data = maybe_convert_index(self._get_ax(0), self.data)

x = data.index # dummy, not used
plotf = self._ts_plot
Expand Down Expand Up @@ -1142,24 +1145,18 @@ def _plot(

@classmethod
def _ts_plot(cls, ax: "Axes", x, data, style=None, **kwds):
from pandas.plotting._matplotlib.timeseries import (
_decorate_axes,
_maybe_resample,
format_dateaxis,
)

# accept x to be consistent with normal plot func,
# x is not passed to tsplot as it uses data.index as x coordinate
# column_num must be in kwds for stacking purpose
freq, data = _maybe_resample(data, ax, kwds)
freq, data = maybe_resample(data, ax, kwds)

# Set ax with freq info
_decorate_axes(ax, freq, kwds)
decorate_axes(ax, freq, kwds)
# digging deeper
if hasattr(ax, "left_ax"):
_decorate_axes(ax.left_ax, freq, kwds)
decorate_axes(ax.left_ax, freq, kwds)
if hasattr(ax, "right_ax"):
_decorate_axes(ax.right_ax, freq, kwds)
decorate_axes(ax.right_ax, freq, kwds)
ax._plot_data.append((data, cls._kind, kwds))

lines = cls._plot(ax, data.index, data.values, style=style, **kwds)
Expand Down
10 changes: 5 additions & 5 deletions pandas/plotting/_matplotlib/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# Plotting functions and monkey patches


def _maybe_resample(series: "Series", ax: "Axes", kwargs):
def maybe_resample(series: "Series", ax: "Axes", kwargs):
# resample against axes freq if necessary
freq, ax_freq = _get_freq(ax, series)

Expand Down Expand Up @@ -105,7 +105,7 @@ def _replot_ax(ax: "Axes", freq, kwargs):
ax._plot_data = []
ax.clear()

_decorate_axes(ax, freq, kwargs)
decorate_axes(ax, freq, kwargs)

lines = []
labels = []
Expand All @@ -128,7 +128,7 @@ def _replot_ax(ax: "Axes", freq, kwargs):
return lines, labels


def _decorate_axes(ax: "Axes", freq, kwargs):
def decorate_axes(ax: "Axes", freq, kwargs):
"""Initialize axes for time-series plotting"""
if not hasattr(ax, "_plot_data"):
ax._plot_data = []
Expand Down Expand Up @@ -193,7 +193,7 @@ def _get_freq(ax: "Axes", series: "Series"):
return freq, ax_freq


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

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


def _maybe_convert_index(ax: "Axes", data):
def maybe_convert_index(ax: "Axes", data):
# tsplot converts automatically, but don't want to convert index
# over and over for DataFrames
if isinstance(data.index, (ABCDatetimeIndex, ABCPeriodIndex)):
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/indexing/multiindex/test_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pandas as pd
from pandas import DataFrame, Index, MultiIndex, Series, Timestamp
import pandas._testing as tm
from pandas.core.indexing import _non_reducing_slice
from pandas.core.indexing import non_reducing_slice
from pandas.tests.indexing.common import _mklbl


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

result = df.loc[tslice_]
expected = pd.DataFrame({("b", "d"): [4, 1]})
Expand Down
12 changes: 6 additions & 6 deletions pandas/tests/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import pandas as pd
from pandas import DataFrame, Index, NaT, Series
import pandas._testing as tm
from pandas.core.indexing import _maybe_numeric_slice, _non_reducing_slice
from pandas.core.indexing import maybe_numeric_slice, non_reducing_slice
from pandas.tests.indexing.common import _mklbl

# ------------------------------------------------------------------------
Expand Down Expand Up @@ -822,7 +822,7 @@ def test_range_in_series_indexing(self, size):
def test_non_reducing_slice(self, slc):
df = DataFrame([[0, 1], [2, 3]])

tslice_ = _non_reducing_slice(slc)
tslice_ = non_reducing_slice(slc)
assert isinstance(df.loc[tslice_], DataFrame)

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

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

result = _maybe_numeric_slice(df, None, include_bool=True)
result = maybe_numeric_slice(df, None, include_bool=True)
expected = pd.IndexSlice[:, ["A", "C"]]
result = _maybe_numeric_slice(df, [1])
result = maybe_numeric_slice(df, [1])
expected = [1]
assert result == expected

Expand Down