Skip to content

[GOOD FIRST ISSUE] Add pre-check for empty links in LinkPredictor #102

@raphael-intugle

Description

@raphael-intugle

name: Good First Issue
about: A beginner-friendly task perfect for first-time contributors
title: '[GOOD FIRST ISSUE] Add pre-check for empty links in LinkPredictor'
labels: 'good first issue'
assignees: ''

Welcome! 👋

This is a beginner-friendly issue perfect for first-time contributors to the Intugle project. We've designed this task to help you get familiar with our codebase while making a meaningful contribution.

Task Description

The LinkPredictor.predict method calls save_yaml without first checking if any links were actually found. If self.links is empty, save_yaml will raise a NoLinksFoundError, which is currently handled after the call. The check for empty links should be moved before the call to save_yaml to prevent unnecessary error handling and improve logic flow.

Why This Matters

By performing the check before calling save_yaml, we make the code more robust and prevent an unnecessary exception from being raised. This improves the clarity of the code and makes error handling more efficient, as the save_yaml method will only be called when there are actual links to save.

What You'll Learn

  • How to improve error handling and control flow in Python.
  • Understanding the LinkPredictor class and its interaction with save_yaml.
  • Best practices for defensive programming.

Step-by-Step Guide

Prerequisites

  • Python 3.10+ installed
  • Git basics (clone, commit, push, pull request)
  • Read our CONTRIBUTING.md guide

Setup Instructions

  1. Fork and clone the repository

    git clone https://github.com/YOUR_USERNAME/data-tools.git
    cd data-tools
  2. Create a virtual environment

    python -m venv .venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  3. Install dependencies

    pip install -e ".[dev]"
  4. Create a new branch

    git checkout -b fix/issue-NUMBER-pre-check-empty-links

Implementation Steps

  1. Locate the predict method: Open src/intugle/link_predictor/predictor.py and find the predict method.
  2. Identify the save_yaml call: Find the line self.save_yaml(file_path=filename).
  3. Add a conditional check: Before this line, add an if statement to check if len(self.links) == 0. If it is, print a warning message (similar to the existing one) and return self to exit the method early.
  4. Remove redundant check: Remove the existing if len(self.links) == 0: block that is currently after the save_yaml call.

Files to Modify

  • File: src/intugle/link_predictor/predictor.py
    • Change: Add a pre-check for empty self.links before calling save_yaml in the predict method.
    • Line(s): Around lines 150-160.

Testing Your Changes

# Run tests
pytest tests/

# You might need to create a simple test case that simulates a scenario where no links are found
# to verify the new logic. For example, by providing datasets that have no common columns.

Submitting Your Work

  1. Commit your changes

    git add .
    git commit -m "Fix: Add pre-check for empty links before saving in LinkPredictor"
  2. Push to your fork

    git push origin fix/issue-NUMBER-pre-check-empty-links
  3. Create a Pull Request

    • Go to the original repository
    • Click "Pull Requests" → "New Pull Request"
    • Select your branch
    • Fill out the PR template
    • Reference this issue with "Fixes #ISSUE_NUMBER"

Expected Outcome

The predict method will gracefully handle cases where no links are found by printing a warning and returning early, without attempting to save an empty relationships file.

Definition of Done

  • Code changes implemented
  • Tests added/updated (if applicable, otherwise ensure existing tests pass)
  • Tests passing locally
  • Code follows project style guidelines
  • No new linter warnings
  • Documentation updated (if needed)
  • Pull request submitted

Resources

Need Help?

Don't hesitate to ask questions! We're here to help you succeed.

Skills You'll Use

  • Python basics
  • Git and GitHub
  • Testing with pytest (optional)

Thank you for contributing to Intugle!

Tips for Success:

  • Take your time and read through everything carefully
  • Don't be afraid to ask questions
  • Test your changes before submitting
  • Have fun! 🎉

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions