diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 002d8640f109d..9073a1e31dfb0 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -63,7 +63,7 @@ _transform_template, get_groupby, ) -from pandas.core.index import Index, MultiIndex, _all_indexes_same +from pandas.core.indexes.api import Index, MultiIndex, all_indexes_same import pandas.core.indexes.base as ibase from pandas.core.internals import BlockManager, make_block from pandas.core.series import Series @@ -1186,7 +1186,7 @@ def first_not_none(values): if isinstance(v, (np.ndarray, Index, Series)): if isinstance(v, Series): applied_index = self._selected_obj._get_axis(self.axis) - all_indexed_same = _all_indexes_same([x.index for x in values]) + all_indexed_same = all_indexes_same([x.index for x in values]) singular_series = len(values) == 1 and applied_index.nlevels == 1 # GH3596 diff --git a/pandas/core/index.py b/pandas/core/index.py index d308ac1a9b1c7..84b37b8bd659d 100644 --- a/pandas/core/index.py +++ b/pandas/core/index.py @@ -13,13 +13,9 @@ RangeIndex, TimedeltaIndex, UInt64Index, - _all_indexes_same, - _get_combined_index, - _get_consensus_names, - _get_objs_combined_axis, _new_Index, - _union_indexes, ensure_index, ensure_index_from_sequences, + get_objs_combined_axis, ) from pandas.core.indexes.multi import _sparsify # noqa:F401 diff --git a/pandas/core/indexes/api.py b/pandas/core/indexes/api.py index 86d55ce2e7cc3..a7cf2c20b0dec 100644 --- a/pandas/core/indexes/api.py +++ b/pandas/core/indexes/api.py @@ -6,23 +6,23 @@ import pandas.core.common as com from pandas.core.indexes.base import ( Index, + InvalidIndexError, _new_Index, ensure_index, ensure_index_from_sequences, ) -from pandas.core.indexes.base import InvalidIndexError # noqa:F401 -from pandas.core.indexes.category import CategoricalIndex # noqa:F401 +from pandas.core.indexes.category import CategoricalIndex from pandas.core.indexes.datetimes import DatetimeIndex -from pandas.core.indexes.interval import IntervalIndex # noqa:F401 -from pandas.core.indexes.multi import MultiIndex # noqa:F401 -from pandas.core.indexes.numeric import ( # noqa:F401 +from pandas.core.indexes.interval import IntervalIndex +from pandas.core.indexes.multi import MultiIndex +from pandas.core.indexes.numeric import ( Float64Index, Int64Index, NumericIndex, UInt64Index, ) from pandas.core.indexes.period import PeriodIndex -from pandas.core.indexes.range import RangeIndex # noqa:F401 +from pandas.core.indexes.range import RangeIndex from pandas.core.indexes.timedeltas import TimedeltaIndex _sort_msg = textwrap.dedent( @@ -57,15 +57,14 @@ "NaT", "ensure_index", "ensure_index_from_sequences", - "_get_combined_index", - "_get_objs_combined_axis", - "_union_indexes", - "_get_consensus_names", - "_all_indexes_same", + "get_objs_combined_axis", + "union_indexes", + "get_consensus_names", + "all_indexes_same", ] -def _get_objs_combined_axis(objs, intersect=False, axis=0, sort=True): +def get_objs_combined_axis(objs, intersect=False, axis=0, sort=True): """ Extract combined index: return intersection or union (depending on the value of "intersect") of indexes on given axis, or None if all objects @@ -137,7 +136,7 @@ def _get_combined_index(indexes, intersect=False, sort=False): for other in indexes[1:]: index = index.intersection(other) else: - index = _union_indexes(indexes, sort=sort) + index = union_indexes(indexes, sort=sort) index = ensure_index(index) if sort: @@ -148,7 +147,7 @@ def _get_combined_index(indexes, intersect=False, sort=False): return index -def _union_indexes(indexes, sort=True): +def union_indexes(indexes, sort=True): """ Return the union of indexes. @@ -217,7 +216,7 @@ def conv(i): return _unique_indices(indexes) - name = _get_consensus_names(indexes)[0] + name = get_consensus_names(indexes)[0] if name != index.name: index = index._shallow_copy(name=name) return index @@ -264,7 +263,7 @@ def _sanitize_and_check(indexes): return indexes, "array" -def _get_consensus_names(indexes): +def get_consensus_names(indexes): """ Give a consensus 'names' to indexes. @@ -289,7 +288,7 @@ def _get_consensus_names(indexes): return [None] * indexes[0].nlevels -def _all_indexes_same(indexes): +def all_indexes_same(indexes): """ Determine if all indexes contain the same elements. diff --git a/pandas/core/internals/construction.py b/pandas/core/internals/construction.py index c24fb0a7dc39a..2980deb9a052c 100644 --- a/pandas/core/internals/construction.py +++ b/pandas/core/internals/construction.py @@ -37,13 +37,9 @@ from pandas.core import algorithms, common as com from pandas.core.arrays import Categorical from pandas.core.construction import sanitize_array -from pandas.core.index import ( - Index, - _get_objs_combined_axis, - _union_indexes, - ensure_index, -) +from pandas.core.index import Index, ensure_index, get_objs_combined_axis from pandas.core.indexes import base as ibase +from pandas.core.indexes.api import union_indexes from pandas.core.internals import ( create_block_manager_from_arrays, create_block_manager_from_blocks, @@ -345,9 +341,9 @@ def extract_index(data): raise ValueError("If using all scalar values, you must pass an index") if have_series: - index = _union_indexes(indexes) + index = union_indexes(indexes) elif have_dicts: - index = _union_indexes(indexes, sort=False) + index = union_indexes(indexes, sort=False) if have_raw_arrays: lengths = list(set(raw_lengths)) @@ -493,7 +489,7 @@ def _list_to_arrays(data, columns, coerce_float=False, dtype=None): def _list_of_series_to_arrays(data, columns, coerce_float=False, dtype=None): if columns is None: - columns = _get_objs_combined_axis(data, sort=False) + columns = get_objs_combined_axis(data, sort=False) indexer_cache = {} diff --git a/pandas/core/reshape/concat.py b/pandas/core/reshape/concat.py index 3c1b2b1eb11d2..3efe8072d3323 100644 --- a/pandas/core/reshape/concat.py +++ b/pandas/core/reshape/concat.py @@ -13,11 +13,11 @@ ) import pandas.core.common as com from pandas.core.generic import NDFrame -from pandas.core.index import ( - _all_indexes_same, - _get_consensus_names, - _get_objs_combined_axis, +from pandas.core.indexes.api import ( + all_indexes_same, ensure_index, + get_consensus_names, + get_objs_combined_axis, ) import pandas.core.indexes.base as ibase from pandas.core.internals import concatenate_block_managers @@ -523,7 +523,7 @@ def _get_new_axes(self): def _get_comb_axis(self, i): data_axis = self.objs[0]._get_block_manager_axis(i) try: - return _get_objs_combined_axis( + return get_objs_combined_axis( self.objs, axis=data_axis, intersect=self.intersect, sort=self.sort ) except IndexError: @@ -617,7 +617,7 @@ def _make_concat_multiindex(indexes, keys, levels=None, names=None) -> MultiInde else: levels = [ensure_index(x) for x in levels] - if not _all_indexes_same(indexes): + if not all_indexes_same(indexes): codes_list = [] # things are potentially different sizes, so compute the exact codes @@ -660,7 +660,7 @@ def _make_concat_multiindex(indexes, keys, levels=None, names=None) -> MultiInde ) # also copies - names = names + _get_consensus_names(indexes) + names = names + get_consensus_names(indexes) return MultiIndex( levels=levels, codes=codes_list, names=names, verify_integrity=False diff --git a/pandas/core/reshape/pivot.py b/pandas/core/reshape/pivot.py index 404292fe4d539..ae8f04ce2569c 100644 --- a/pandas/core/reshape/pivot.py +++ b/pandas/core/reshape/pivot.py @@ -9,7 +9,7 @@ import pandas.core.common as com from pandas.core.frame import _shared_docs from pandas.core.groupby import Grouper -from pandas.core.index import Index, MultiIndex, _get_objs_combined_axis +from pandas.core.index import Index, MultiIndex, get_objs_combined_axis from pandas.core.reshape.concat import concat from pandas.core.reshape.util import cartesian_product from pandas.core.series import Series @@ -541,7 +541,7 @@ def crosstab( rownames = _get_names(index, rownames, prefix="row") colnames = _get_names(columns, colnames, prefix="col") - common_idx = _get_objs_combined_axis(index + columns, intersect=True, sort=False) + common_idx = get_objs_combined_axis(index + columns, intersect=True, sort=False) data = {} data.update(zip(rownames, index)) diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index 90f8fbc5faef2..8ffceb491aa86 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -33,12 +33,8 @@ period_range, ) from pandas.core.algorithms import safe_sort -from pandas.core.index import ( - _get_combined_index, - ensure_index, - ensure_index_from_sequences, -) -from pandas.core.indexes.api import Index, MultiIndex +from pandas.core.index import ensure_index, ensure_index_from_sequences +from pandas.core.indexes.api import Index, MultiIndex, _get_combined_index from pandas.tests.indexes.common import Base from pandas.tests.indexes.conftest import indices_dict import pandas.util.testing as tm