Skip to content

CLN: explicit kwargs and docstring for create_index #29971

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
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
40 changes: 33 additions & 7 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1191,13 +1191,31 @@ def append_to_multiple(

self.append(k, val, data_columns=dc, **kwargs)

def create_table_index(self, key: str, **kwargs):
def create_table_index(
self,
key: str,
columns=None,
optlevel: Optional[int] = None,
kind: Optional[str] = None,
):
"""
Create a pytables index on the table.

Parameters
----------
key : str
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 columns.
* None : Create indexes on all columns.
* listlike : Create indexes on the given columns.

optlevel : int or None, default None
Optimization level, if None, pytables defaults to 6.
kind : str or None, default None
Kind of index, if None, pytables defaults to "medium"

Raises
------
Expand All @@ -1212,7 +1230,7 @@ def create_table_index(self, key: str, **kwargs):

if not isinstance(s, Table):
raise TypeError("cannot create table index on a Fixed format store")
s.create_index(**kwargs)
s.create_index(columns=columns, optlevel=optlevel, kind=kind)

def groups(self):
"""
Expand Down Expand Up @@ -3526,18 +3544,26 @@ def f(i, c):

return self._indexables

def create_index(self, columns=None, optlevel=None, kind=None):
def create_index(self, columns=None, optlevel=None, kind: Optional[str] = None):
"""
Create a pytables index on the specified columns
note: cannot index Time64Col() or ComplexCol currently;
PyTables must be >= 3.0

Parameters
----------
columns : False (don't create an index), True (create all columns
index), None or list_like (the indexers to index)
optlevel: optimization level (defaults to 6)
kind : kind of index (defaults to 'medium')
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 columns.
* None : Create indexes on all columns.
* listlike : Create indexes on the given columns.

optlevel : int or None, default None
Optimization level, if None, pytables defaults to 6.
kind : str or None, default None
Kind of index, if None, pytables defaults to "medium"

Raises
------
Expand Down