Skip to content

Type err fix#4

Merged
myui merged 5 commits intomainfrom
type_err_fix
Jun 6, 2025
Merged

Type err fix#4
myui merged 5 commits intomainfrom
type_err_fix

Conversation

@myui
Copy link
Copy Markdown
Owner

@myui myui commented Jun 6, 2025

This pull request introduces several updates across multiple files to improve type annotations, enhance model functionality, and refine error handling. The most notable changes include the addition of type hints, adjustments to model initialization and training, and improved handling of cold-start users and batch recommendations.

Type Annotations and Type Ignoring

  • rtrec/models/base.py: Added type hints for return values and parameters in multiple methods, including recommend, recommend_batch, and _similar_items. Type ignoring was applied for compatibility with certain operations. [1] [2]
  • rtrec/models/internal/slim_elastic.py: Updated type annotations for properties and methods, such as shape and set_col. Type ignoring was applied to ensure compatibility with sparse matrix operations. [1] [2] [3]

Model Updates and Enhancements

  • rtrec/experiments/experiments.py: Replaced older models (Fast_SLIM_MSE, SLIM_MSE) with newer ones (SLIM, LightFM, HybridSlimFM) and updated their initialization parameters for better configurability. [1] [2]
  • rtrec/models/hybrid.py: Enhanced methods like fit, _fit_recorded, and bulk_fit to return Self for method chaining. Added type ignoring for compatibility with sparse matrix operations. [1] [2] [3]

Cold-Start and Batch Recommendations

  • rtrec/models/base.py: Improved handling of cold-start users by setting user_id to None when exceeding max_user_id.
  • rtrec/models/hybrid.py: Refined batch recommendation methods (_recommend_cold_batch, _recommend_hot_batch) to ensure compatibility with numpy operations and added type ignoring for matrix manipulations. [1] [2]

Error Handling Improvements

These changes collectively improve the robustness, readability, and functionality of the codebase.

myui added 5 commits May 22, 2025 14:15
- Add type hints and annotations across the codebase
- Fix return type annotations in the SLIM model
- Add proper type handling for matrix operations
- Fix dimension checks in matrix operations
- Handle potential None values in LightFM wrapper
- Improve handling of cold-start users in recommendation pipeline
- Add proper error checking for feature vector operations
@myui myui requested a review from Copilot June 6, 2025 04:16
@myui myui self-assigned this Jun 6, 2025
@myui myui merged commit aecb7b8 into main Jun 6, 2025
1 check passed
@myui myui deleted the type_err_fix branch June 6, 2025 04:17
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances type annotations across utilities and models, adds method chaining for model fitting, and refines error handling and cold-start logic.

  • Broadly updates type hints and adds Self return types for chaining in SLIM, LightFM, HybridSlimFM
  • Improves cold-start and batch recommendation handling in base and hybrid models
  • Refines error checks in lightfm wrapper and parallel SLIM elastic, plus minor utility tweaks

Reviewed Changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.

Show a summary per file
File Description
rtrec/utils/pandas.py Switched to_numeric error mode to raise and catch; numeric parse update
rtrec/utils/lru.py Added @override, standardized add/discard signatures
rtrec/utils/interactions.py Broadened matrix conversion signatures to use Optional
rtrec/utils/features.py Parameterized IndexedSet constructor with generics
rtrec/utils/collections.py Made IndexedSet a generic class
rtrec/tools/kinesis_consumer.py Swapped outdated Fast_SLIM_MSE import for new SLIM model
rtrec/models/slim.py Added Self returns to fit methods; expanded _similar_items return type
rtrec/models/lightfm.py Added Self returns, inserted # type: ignore for numpy/sparse ops
rtrec/models/internal/slim_elastic.py Refined type hints, safer CPU count fallback for parallel fitting
rtrec/models/internal/lightfm_wrapper.py Added initialization checks before resizing embeddings
rtrec/models/hybrid.py Added Self returns, improved type hints and cold/hot batch logic
rtrec/models/base.py Updated recommend/_similar_items annotations and cold-start ID logic
rtrec/experiments/experiments.py Replaced old model names with SLIM, LightFM, HybridSlimFM
rtrec/experiments/datasets.py Removed stale header comments
Comments suppressed due to low confidence (5)

rtrec/utils/pandas.py:10

  • The code uses np.integer but numpy (as np) is not imported in this module. Add import numpy as np at the top or replace with a pandas-native type check.
df.loc[:, df.dtypes == np.integer] = df.loc[:, df.dtypes == np.integer].apply(parse_numeric, downcast="integer")

rtrec/utils/lru.py:20

  • [nitpick] The add and discard methods use the parameter name value, but docstrings and __contains__ use key. Consider unifying to a single name for clarity.
def add(self, value: Any) -> None:

rtrec/utils/interactions.py:237

  • The signature uses Optional[List[int]] but Optional is not imported—add from typing import Optional.
def to_csr(self, select_users: Optional[List[int]] = None, include_weights: bool = True) -> csr_matrix:

rtrec/models/internal/slim_elastic.py:289

  • The code calls os.cpu_count() but os is not imported in this module. Add import os at the top.
cpu_count = os.cpu_count()

rtrec/experiments/experiments.py:53

  • The fit call no longer passes an epochs argument, which may mismatch the expected signature of Recommender.fit. Confirm the updated fit signature or reintroduce the epochs parameter.
recommender.fit(train_data, batch_size=batch_size)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants