Skip to content

Fix type errors#3

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

Fix type errors#3
myui merged 4 commits intomainfrom
type_err_fix

Conversation

@myui
Copy link
Copy Markdown
Owner

@myui myui commented May 22, 2025

This pull request introduces several updates, including the addition of new models, type annotations, and method return type changes across multiple files. It also includes refactoring for consistency and improved functionality in matrix operations, feature handling, and interaction processing. Below is a summary of the most important changes grouped by theme:

Model Enhancements and Refactoring:

  • Replaced Fast_SLIM_MSE and SLIM_MSE with SLIM, LightFM, and HybridSlimFM models in rtrec/experiments/experiments.py, updating the run_experiment function to support these new models. [1] [2]
  • Updated the Kinesis consumer to use the SLIM model instead of Fast_SLIM_MSE for training.

Type Annotations and Method Return Types:

  • Introduced the Self type annotation in models (rtrec/models/hybrid.py, rtrec/models/lightfm.py, and rtrec/models/slim.py) and updated methods like bulk_fit, fit, and _fit_recorded to return self for method chaining. [1] [2] [3]
  • Improved type annotations for matrix operations, such as shape properties and feature-building methods, ensuring stricter type definitions. [1] [2]

Interaction and Feature Handling:

  • Refactored to_csr, to_csc, and to_coo methods in rtrec/utils/interactions.py to use Optional[List[int]] for optional parameters, enhancing flexibility and readability. [1] [2] [3]
  • Updated FeatureStore to remove explicit string type for IndexedSet attributes, allowing for broader use cases.

Code Consistency and Cleanup:

  • Added @override decorators to methods in rtrec/utils/lru.py to indicate overridden methods from parent classes, improving code clarity. [1] [2]
  • Changed the convert_dtypes function in rtrec/utils/pandas.py to raise errors during numeric conversion for stricter data handling.

Miscellaneous:

  • Removed unused imports in rtrec/experiments/datasets.py for better code hygiene.

@myui myui requested a review from Copilot May 22, 2025 05:16
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 replaces deprecated SLIM models with SLIM, LightFM, and HybridSlimFM, adds Self return type annotations for method chaining, refines type hints in utilities, and tightens numeric conversion in pandas utilities.

  • Refactored model selections in experiments and updated run_experiment signature
  • Updated fit/bulk_fit methods across models to return Self and added @override decorators
  • Improved type hints (Optional[List[int]], removed generics for IndexedSet, stricter to_numeric behavior)

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
rtrec/utils/pandas.py Changed to_numeric to raise on error for stricter validation
rtrec/utils/lru.py Added @override, renamed parameters and updated signatures
rtrec/utils/interactions.py Made select_users/select_items parameters truly optional
rtrec/utils/features.py Removed generic arguments from IndexedSet declarations and fixed type hint on build_item_features_matrix
rtrec/tools/kinesis_consumer.py Swapped out deprecated Fast_SLIM_MSE import for SLIM
rtrec/models/slim.py Added Self return to fit methods for chaining
rtrec/models/lightfm.py Added Self return to bulk_fit and _fit_recorded, silenced type errors on .shape
rtrec/models/internal/slim_elastic.py Tightened return type on .shape properties
rtrec/models/hybrid.py Added Self return to bulk_fit
rtrec/experiments/experiments.py Replaced old model names with new ones and updated fit call
Comments suppressed due to low confidence (2)

rtrec/utils/lru.py:25

  • The parameter name in the docstring (key) no longer matches the method signature (value). Update the docblock to refer to value for consistency.
key (Any): The key to add or update.

rtrec/experiments/experiments.py:53

  • The call to fit no longer passes epochs or random_seed. Verify that Recommender.fit signature has been updated accordingly or document this breaking change.
recommender.fit(train_data, batch_size=batch_size)

Comment thread rtrec/utils/lru.py
Comment thread rtrec/utils/features.py Outdated
Comment thread rtrec/models/slim.py
Comment thread rtrec/models/lightfm.py
myui added 3 commits May 23, 2025 16:32
- 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 merged commit 097e85c into main Jun 5, 2025
1 check passed
@myui myui deleted the type_err_fix branch June 5, 2025 05:31
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