openml-python
openml-python copied to clipboard
feat: Add CLI Commands for Browsing and Searching OpenML Studies
This commit implements CLI commands for browsing and searching OpenML studies and benchmark suites, addressing issue #1506.
Features Added:
1. Studies List Command ()
- Lists studies and/or benchmark suites with optional filtering
- Supports filtering by:
- Status (active, in_preparation, deactivated, all)
- Uploader ID
- Type (study, suite, or all)
- Size and offset for pagination
- Three output formats: list (default), table, json
- Verbose mode shows detailed information
2. Studies Info Command ()
- Displays detailed information about a specific study or suite
- Automatically detects whether ID refers to a study or suite
- Shows study metadata, description, and entity counts
- Verbose mode displays first 10 IDs of associated entities
3. Studies Search Command ()
- Case-insensitive search by name or alias
- Searches both studies and suites simultaneously
- Optional status filtering
- Multiple output formats supported
- Verbose mode for detailed results
Implementation Details:
- Added imports for study functions and types (OpenMLStudy, OpenMLBenchmarkSuite)
- Created helper functions for formatting:
- _format_studies_output(): Routes to appropriate formatter
- _format_studies_table(): Displays studies in tabular format
- _format_studies_list(): Displays studies as simple list
- _display_study_entity_counts(): Shows entity counts
- _display_study_entity_ids(): Shows first 10 entity IDs
- Main command functions:
- studies_list(): Handles listing with filters
- studies_info(): Displays detailed study information
- studies_search(): Performs search operations
- studies(): Dispatcher for routing subcommands
- Updated main() to register studies subparser with all arguments
- Added proper type annotations using Union types
Testing:
- Created comprehensive test suite with 19 tests
- All tests passing (19/19)
- Tests cover:
- Listing studies, suites, and combined results
- Filtering by status, uploader, and type
- Info display for studies and suites
- Fallback from study to suite
- Search functionality with various filters
- Different output formats (list, table, json)
- Verbose mode
- Dispatcher routing
- Error handling
Code Quality:
- All pre-commit checks passing:
- ruff: Passed
- ruff-format: Passed
- mypy: Passed (with proper Union type annotations)
- Code complexity kept under limits through helper function extraction
- Proper error handling with informative messages
- Follows existing CLI patterns and conventions
Related: #1506