MCPcopy
hub / github.com/pandas-dev/pandas / create_index

Method create_index

pandas/io/pytables.py:3888–3972  ·  view source on GitHub ↗

Create a pytables index on the specified columns. Parameters ---------- columns : None, bool, or listlike[str] Indicate which columns to create an index on. * False : Do not create any indexes. * True : Create indexes on all colu

(
        self, columns=None, optlevel=None, kind: str | None = None
    )

Source from the content-addressed store, hash-verified

3886 return _indexables
3887
3888 def create_index(
3889 self, columns=None, optlevel=None, kind: str | None = None
3890 ) -> None:
3891 """
3892 Create a pytables index on the specified columns.
3893
3894 Parameters
3895 ----------
3896 columns : None, bool, or listlike[str]
3897 Indicate which columns to create an index on.
3898
3899 * False : Do not create any indexes.
3900 * True : Create indexes on all columns.
3901 * None : Create indexes on all columns.
3902 * listlike : Create indexes on the given columns.
3903
3904 optlevel : int or None, default None
3905 Optimization level, if None, pytables defaults to 6.
3906 kind : str or None, default None
3907 Kind of index, if None, pytables defaults to "medium".
3908
3909 Raises
3910 ------
3911 TypeError if trying to create an index on a complex-type column.
3912
3913 Notes
3914 -----
3915 Cannot index Time64Col or ComplexCol.
3916 Pytables must be >= 3.0.
3917 """
3918 if not self.infer_axes():
3919 return
3920 if columns is False:
3921 return
3922
3923 # index all indexables and data_columns
3924 if columns is None or columns is True:
3925 columns = [a.cname for a in self.axes if a.is_data_indexable]
3926 if not isinstance(columns, (tuple, list)):
3927 columns = [columns]
3928
3929 kw = {}
3930 if optlevel is not None:
3931 kw["optlevel"] = optlevel
3932 if kind is not None:
3933 kw["kind"] = kind
3934
3935 table = self.table
3936 for c in columns:
3937 v = getattr(table.cols, c, None)
3938 if v is not None:
3939 # remove the index if the kind/optlevel have changed
3940 if v.is_indexed:
3941 index = v.index
3942 cur_optlevel = index.optlevel
3943 cur_kind = index.kind
3944
3945 if kind is not None and cur_kind != kind:

Callers 2

create_table_indexMethod · 0.45
_write_to_groupMethod · 0.45

Calls 2

infer_axesMethod · 0.80
startswithMethod · 0.80

Tested by

no test coverage detected