Skip to content

utils

Utility module for RecNextEval library.

This module provides a set of general utility functions used throughout RecNextEval. It includes utilities for file handling, configuration, matrix operations, and logging.

Utility Functions

General-purpose utility functions that support library operations:

  • create_config_yaml: Create configuration YAML file
  • safe_dir: Safely manage directory operations
  • add_columns_to_csr_matrix: Add columns to sparse matrix
  • add_rows_to_csr_matrix: Add rows to sparse matrix
  • arg_to_str: Convert arguments to string representation
  • df_to_sparse: Convert DataFrame to sparse matrix
  • to_binary: Convert data to binary format
  • to_tuple: Convert data to tuple format
  • ProgressBar: Progress bar utility for tracking operations

Path Utilities

Directory and path management functions:

  • get_cache_dir: Get cache directory path
  • get_data_dir: Get data directory path
  • get_logs_dir: Get logs directory path
  • get_repo_root: Get repository root directory
  • safe_dir: Safely create and manage directories

Logging Control

Functions to control logging level and warning suppression:

  • log_level: Get current logging level
  • log_level_by_name: Set logging level by name (DEBUG, INFO, WARNING, ERROR)
  • prepare_logger: Initialize logger for RecNextEval
  • suppress_warnings: Suppress all Python warnings
  • suppress_specific_warnings: Suppress specific warning types

Logging Example

import logging
import warnings
import recnexteval

# Set log level to INFO
recnexteval.log_level_by_name("INFO")

# Suppress all warnings
recnexteval.suppress_warnings(suppress=True)

# Log information
logger = logging.getLogger("recnexteval")
logger.info("This is an informational message.")

# Warnings will be suppressed
warnings.warn("This warning will not appear.")

Configuration

  • create_config_yaml: Generate configuration YAML file for RecNextEval