CategoricalIndex ================ .. currentmodule:: pandasCore .. class:: CategoricalIndex Index based on an underlying Categorical. Example ------- .. code-block:: python import pandasCore as pd # Create CategoricalIndex idx = pd.CategoricalIndex([1, 2, 3], name='my_index') print(len(idx)) # 3 Attributes ---------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Attribute - Description - Example * - :attr:`~CategoricalIndex.categories` - - * - :attr:`~CategoricalIndex.codes` - - * - :attr:`~CategoricalIndex.dtype` - - * - :attr:`~CategoricalIndex.empty` - - * - :attr:`~CategoricalIndex.name` - - * - :attr:`~CategoricalIndex.ordered` - - * - :attr:`~CategoricalIndex.size` - - Construction ------------ .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~CategoricalIndex.__init__` ``(data: object = None, categories: object = None, ordered: object = None, dtype: object = None, copy: bool = False, name: object = None)`` - - :ref:`View ` Statistics ---------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~CategoricalIndex.max` ``()`` - - * - :meth:`~CategoricalIndex.min` ``()`` - - * - :meth:`~CategoricalIndex.nunique` ``()`` - - Comparison ---------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~CategoricalIndex.__eq__` ``(value: str)`` - - * - :meth:`~CategoricalIndex.__ge__` ``(value: str)`` - - * - :meth:`~CategoricalIndex.__gt__` ``(value: str)`` - - * - :meth:`~CategoricalIndex.__le__` ``(value: str)`` - - * - :meth:`~CategoricalIndex.__lt__` ``(value: str)`` - - * - :meth:`~CategoricalIndex.__ne__` ``(value: str)`` - - * - :meth:`~CategoricalIndex.equals` ``(other: pandasCore.CategoricalIndex)`` - - I/O --- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~CategoricalIndex.tolist` ``()`` - - Conversion ---------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~CategoricalIndex.copy` ``()`` - - Iteration --------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~CategoricalIndex.__len__` ``()`` - - Set Operations -------------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~CategoricalIndex.unique` ``()`` - - Categorical Methods ------------------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~CategoricalIndex.add_categories` ``(new_categories: collections.abc.Sequence[str])`` - - * - :meth:`~CategoricalIndex.as_ordered` ``()`` - - * - :meth:`~CategoricalIndex.as_unordered` ``()`` - - * - :meth:`~CategoricalIndex.remove_categories` ``(removals: collections.abc.Sequence[str])`` - - * - :meth:`~CategoricalIndex.rename_categories` ``(new_categories: object)`` - - * - :meth:`~CategoricalIndex.reorder_categories` ``(new_categories: collections.abc.Sequence[str])`` - - * - :meth:`~CategoricalIndex.set_categories` ``(new_categories: collections.abc.Sequence[str], rename: bool = False)`` - - Other Methods ------------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~CategoricalIndex.__hash__` ``()`` - - * - :meth:`~CategoricalIndex.__repr__` ``()`` - - * - :meth:`~CategoricalIndex.__str__` ``()`` - - Code Examples ------------- The following examples are extracted from the test suite. .. _example-categoricalindex-dunder-initdunder--0: .. dropdown:: __init__ (test_categoricalindex_comp.py:39) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 29 :emphasize-lines: 11 ctx = TestContext() # ==================== Test Functions ==================== def test_categoricalindex_construction(): """Test CategoricalIndex construction with various parameters""" f_print_header("Test: CategoricalIndex Construction") # Basic construction with no arguments pc_idx = pandasCore.CategoricalIndex() ctx.assert_equal(0, len(pc_idx), "CategoricalIndex() - empty") # Construction with data try: pc_idx2 = pandasCore.CategoricalIndex(data=['a', 'b', 'c', 'a', 'b']) pd_idx2 = pd.CategoricalIndex(['a', 'b', 'c', 'a', 'b']) ctx.assert_equal(len(pd_idx2), len(pc_idx2), "CategoricalIndex with data - length") except Exception as e: f_print_warning(f"CategoricalIndex data construction not fully supported: {e}") # Test passes if construction works even without data