Shared functions and methods

Custom Exceptions

Error

class ibmdbpy.exceptions.Error(message)[source]

This is the base class of all other exceptions thrown by ibmdbpy. It can be used to catch all exceptions with a single except statement.

IdaDataBaseError

class ibmdbpy.exceptions.IdaDataBaseError(message)[source]

This exception is raised when an error occurs while you manipulate the IdaDataBase interface.

IdaDataFrameError

class ibmdbpy.exceptions.IdaDataFrameError(message)[source]

This exception is raised when an error occurs while you manipulate the IdaDataFrame interface.

PrimaryKeyError

class ibmdbpy.exceptions.PrimaryKeyError(message)[source]

This exception is raised when an error occurs because of a missing or eroneous primary key column.

IdaKMeansError

class ibmdbpy.exceptions.IdaKMeansError(message)[source]

This exception is raised when an error related to the ibmdbpy KMeans clustering occurs.

IdaAssociationRulesError

class ibmdbpy.exceptions.IdaAssociationRulesError(message)[source]

This exception is raised when an error related to ibmdbpy Association Rules occurs.

IdaNaiveBayesError

class ibmdbpy.exceptions.IdaNaiveBayesError(message)[source]

This exception is raised when an error related to ibmdbpy Naive Bayes occurs.

User Interactions

Configuring the environment

ibmdbpy.utils.set_verbose(is_verbose)[source]

Set the environment variable “VERBOSE” to ‘TRUE’ or ‘FALSE’. If it is set to ‘TRUE’, all SQL request are printed in the console.

ibmdbpy.utils.set_autocommit(is_autocommit)[source]

Set the environment variable “AUTCOMMIT” to ‘TRUE’ or ‘FALSE’. If it is set to ‘TRUE’, all operations are committed automatically.

Performance Monitoring

ibmdbpy.utils.timed(function)[source]

Measure the elapsed time of custom functions of the package. Should be used as a decorator.

User prompt

ibmdbpy.utils.query_yes_no(question, default=None)[source]

Ask a yes/no question via raw_input() and return its answer.

Parameters:

question : str

Question to be asked to the user. Should be a yes/no question.

default : “yes”/”no”

The presumed answer if the user just hits <Enter>.

Returns:

bool

Legagy from benchmark

ibmdbpy.utils.chunklist(l, n)[source]

Yield successive n-sized chunks from l.

ibmdbpy.utils.silent(function)[source]

Decorate that silent the function it decorates, i.e SQL queries will not be printed.

Notes

  • Legagy from Benchmark submodule
ibmdbpy.utils.to_nK(dataframe, nKrow)[source]

Create a version of the dataframe that has n Krows.

Parameters:

dataframe : DataFrame

DataFrame to use as a basis

nKrow : int

Number of Krows the return dataframe should contain

Returns:

DataFrame

A Version of the inputed dataframe with n Krows

Notes

  • If the dataset is smaller than nKrow, it will be imputed randomly

with some existing rows, otherwise ve return a random sample

  • Legagy from Benchmark submodule
ibmdbpy.utils.extend_dataset(df, n)[source]

Extend a dataframe horizontaly by duplicating its columns n times

Convention checking

Name checking

ibmdbpy.utils.check_tablename(tablename)[source]

Check if a string is upper case. This function converts the string to upper case and checks if it is a valid table name.

Parameters:

tablename : str

string to be checked.

Returns:

str

Checked and upper cased table name.

Notes

Table names should consist of upper case characters or numbers that can be separated by underscores (“_”) characters.

ibmdbpy.utils.check_viewname(viewname)[source]

Convenience function. Just an alternative name to check_tablename for checking view names, which have the same prerequisites as tablenames. See the check_tablename documentation.

ibmdbpy.utils.check_case(name)[source]

Check if the name given as parameter is in upper case and convert it to upper cases.

Private functions

_convert_dtypes

ibmdbpy.utils._convert_dtypes(idadf, data)[source]

DEPRECATED - CURRENTLY NOT IN USE was used for formatting dataframe types

Convert datatypes in a dataframe to float or to int according to the corresponding type in database. This function only works if the dataframe that is given as a parameter has the same columns as the current IdaDataFrame.

_reset_attributes

ibmdbpy.utils._reset_attributes(idaobject, attributes)[source]

Delete an attribute of a list of attributes of an object, if the attribute exists.