ops

Miscellaneous operations.

General usage

confirmed([prompt, confirmation_required, resp])

Prompts user for confirmation to proceed.

get_obj_attr(obj[, col_names, as_dataframe])

Retrieves main attributes of an object.

eval_dtype(str_val)

Converts a string representation to its intrinsic data type.

hash_password(password[, salt, salt_size, ...])

Hashes a password using hashlib.pbkdf2_hmac (PBKDF2 algorithm with HMAC-SHA256).

verify_password(password, salt, key[, ...])

Verifies if a password matches the provided salt and key.

func_running_time(func)

Decorator to measure the execution time of a function or class method.

Basic computation / conversion

get_utc_tai_offset([verbose, raise_error, url])

Retrieves the difference between UTC (Coordinated Universal Time) and TAI (International Atomic Time).

gps_time_to_utc(gps_time[, as_datetime, ...])

Converts GPS time to UTC time.

parse_size(size[, binary, precision])

Parses size into human-readable format or vice versa.

get_number_of_chunks(file_or_obj[, ...])

Gets the total number of chunks of a data file, given a minimum chunk size limit.

get_extreme_outlier_bounds(num_dat[, k])

Gets the upper and lower bounds for extreme outliers using the interquartile range method.

interquartile_range(num_dat)

Calculates the interquartile range (IQR) of numerical data.

find_closest_date(date, lookup_dates[, ...])

Finds the closest date to a given date from a list of dates.

Basic data manipulation

Iterable

loop_in_pairs(iterable)

Generates pairs of consecutive elements from the given iterable.

split_list_by_size(lst, sub_len)

Splits a list into evenly sized sub-lists.

split_list(lst, num_of_sub)

Splits a list into a specified number of equally-sized sub-lists.

split_iterable(iterable, chunk_size)

Splits an iterable into evenly sized chunks.

update_dict(dictionary, updates[, inplace])

Updates a (nested) dictionary with another dictionary.

update_dict_keys(dictionary[, replacements])

Updates keys in a (nested) dictionary based on a given replacements dictionary.

get_dict_values(key, dictionary)

Retrieves all values in a (nested) dictionary for a given key.

remove_dict_keys(dictionary, *keys)

Removes multiple keys from a dictionary.

compare_dicts(dict1, dict2)

Compares the differences between two dictionaries.

merge_dicts(*dicts)

Merges multiple dictionaries into a single dictionary.

Tabular data

detect_nan_for_str_column(data_frame[, ...])

Detects if a column with string type contains NaN values for a given dataframe.

create_rotation_matrix(theta)

Creates a 2D rotation matrix for counterclockwise rotation.

dict_to_dataframe(input_dict[, k, v])

Converts a dictionary to a dataframe.

swap_cols(array, c1, c2[, as_list])

Swaps positions of two columns in an array.

swap_rows(array, r1, r2[, as_list])

Swaps positions of two rows in an array.

np_shift(array, step[, fill_value])

Shifts an array by a desired number of rows.

cmap_discretisation(cmap, n_colours)

Creates a discrete colour ramp.

colour_bar_index(cmap, n_colours[, labels])

Creates a colour bar with correctly aligned labels.

Graph plotting

cmap_discretisation(cmap, n_colours)

Creates a discrete colour ramp.

colour_bar_index(cmap, n_colours[, labels])

Creates a colour bar with correctly aligned labels.

Web data manipulation

is_network_connected()

Checks whether the current machine is connected to the Internet.

is_url(url[, partially])

Checks if url is a valid URL.

is_url_connectable(url)

Checks if the current machine can connect to the given URL.

is_downloadable(url[, request_field])

Checks if a URL leads to a webpage where downloadable content is available.

init_requests_session(url[, max_retries, ...])

Instantiates a requests session with configurable retry behaviour.

load_user_agent_strings([shuffled, ...])

Loads user-agent strings for popular web browsers.

get_user_agent_string([fancy])

Gets a random user-agent string for a specified browser.

fake_requests_headers([randomized])

Generates fake HTTP headers.

download_file_from_url(url, path_to_file[, ...])

Downloads a file from a valid URL.

GitHubFileDownloader(repo_url[, ...])

Downloads files from GitHub repositories.