Skip to content

Conversation

@rodrigosnader
Copy link
Contributor

@rodrigosnader rodrigosnader commented Nov 17, 2025

Description

Fixes an error that occurs when trying to fetch comments from YouTube videos that have no comments.

Problem

When a video has no comments, the component would fail with:

KeyError: "['comment_id', 'parent_comment_id', 'is_reply', ...] not in index"

This happened because pd.DataFrame([]) creates an empty DataFrame with no columns, but the code then tried to reorder columns that don't exist.

Solution

  • Define column order once at the beginning to avoid code duplication
  • Check if comments_data is empty before processing
  • When empty: Create DataFrame with all expected columns (but no rows)
  • When not empty: Process normally

Testing

Tested with:

  • Videos with comments ✅
  • Videos with no comments ✅
  • Videos with comments disabled ✅

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Improved handling of video comments retrieval to ensure correct data structure when no comments are available
    • Enhanced column ordering and data consistency for comment data processing across all result scenarios

- Define column order once to avoid code duplication
- Create empty DataFrame with proper schema when no comments exist
- Prevents KeyError when trying to reorder columns on empty DataFrame
- Returns consistent DataFrame structure regardless of comment count
@github-actions github-actions bot added the community Pull Request from an external contributor label Nov 17, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 17, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The get_video_comments function in the YouTube comments module was refactored to conditionally construct DataFrames based on whether comment data is empty, ensuring proper schema handling for empty results while maintaining correct column ordering for non-empty data.

Changes

Cohort / File(s) Summary
YouTube Comments DataFrame Construction
src/lfx/src/lfx/components/youtube/comments.py
Refactored get_video_comments to branch on empty comments state: creates empty DataFrame with column_order if no results, otherwise builds DataFrame from comments_data with injected video_id and video_url metadata, reordered to match column_order. Metrics extension logic (like_count, reply_count) now applied post-DataFrame construction only for non-empty results.

Sequence Diagram

sequenceDiagram
    participant caller as Caller
    participant func as get_video_comments()
    participant df as DataFrame
    
    caller->>func: call with video_id
    func->>func: fetch comments_data
    
    alt comments_data is empty
        func->>df: create empty DataFrame<br/>with column_order schema
    else comments_data exists
        func->>df: build DataFrame<br/>from comments_data
        func->>df: inject video_id,<br/>video_url columns
        func->>df: extend metrics<br/>(like_count, reply_count)
        func->>df: reorder to<br/>column_order
    end
    
    func->>caller: return DataFrame
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Well-contained change to a single function with straightforward branching logic
  • No public API signature modifications
  • Primary focus is ensuring both empty and non-empty code paths produce correctly-schemed DataFrames
  • Areas for attention: Verify both branches (empty and non-empty) produce DataFrames with identical column structure and ordering; test edge cases for empty comment results

Pre-merge checks and finishing touches

Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error, 2 inconclusive)
Check name Status Explanation Resolution
Test Coverage For New Implementations ❌ Error The PR modifies the YouTube Comments component to handle videos with no comments but does not include any test cases to verify the bug fix. Add regression tests that verify the fix handles videos with no comments, videos with comments, and edge cases without raising errors.
Test Quality And Coverage ❓ Inconclusive Repository does not contain the referenced file or any test files; unable to evaluate test quality and coverage. Provide access to the actual repository with the YouTube comments component and its test files to complete this assessment.
Test File Naming And Structure ❓ Inconclusive Repository does not contain accessible test files or visible PR test modifications. Cannot verify test naming patterns and structure requirements without test file access. Provide access to test files added/modified in this PR or confirm whether test coverage was intentionally excluded from this bug fix.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: Handle videos with no comments in YouTube Comments component' clearly and specifically describes the main change: fixing handling of videos with no comments in the YouTube component.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Excessive Mock Usage Warning ✅ Passed The PR contains only source code changes to the YouTube comments component with no test files included, making mock usage assessment not applicable.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added the bug Something isn't working label Nov 17, 2025
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Nov 17, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 17, 2025

Frontend Unit Test Coverage Report

Coverage Summary

Lines Statements Branches Functions
Coverage: 15%
14.68% (3983/27130) 7.57% (1560/20599) 8.94% (535/5982)

Unit Test Results

Tests Skipped Failures Errors Time
1630 0 💤 0 ❌ 0 🔥 18.722s ⏱️

@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Nov 17, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/lfx/src/lfx/components/youtube/comments.py (1)

196-226: Empty-comments handling and column ordering look correct; optional readability tweak

The new column_order + branching logic correctly fixes the KeyError for videos with no comments and keeps the schema consistent between empty and non-empty results for a given include_metrics setting. The non-empty branch also safely injects video_id/video_url before reordering, so all referenced columns exist at selection time. This aligns well with the PR objective.

If you want to tighten readability a bit, you could separate base vs metrics columns, e.g.:

base_columns = [
    "video_id",
    "video_url",
    "comment_id",
    "parent_comment_id",
    "is_reply",
    "author",
    "author_channel_url",
    "text",
    "published_at",
    "updated_at",
]
metric_columns = ["like_count", "reply_count"]
column_order = base_columns + (metric_columns if self.include_metrics else [])

Functionally what you have is already solid, so this is purely optional.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6606ae5 and 5c8308a.

📒 Files selected for processing (1)
  • src/lfx/src/lfx/components/youtube/comments.py (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Update Component Index

@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Nov 17, 2025
@codecov
Copy link

codecov bot commented Nov 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 31.61%. Comparing base (927f96b) to head (584ff7b).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #10633      +/-   ##
==========================================
- Coverage   31.61%   31.61%   -0.01%     
==========================================
  Files        1348     1348              
  Lines       61117    61099      -18     
  Branches     9134     9129       -5     
==========================================
- Hits        19324    19314      -10     
+ Misses      40878    40873       -5     
+ Partials      915      912       -3     
Flag Coverage Δ
backend 51.77% <ø> (ø)
frontend 13.59% <ø> (ø)
lfx 38.92% <ø> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Collaborator

@erichare erichare left a comment

Choose a reason for hiding this comment

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

LGTM!

@github-actions github-actions bot added the lgtm This PR has been approved by a maintainer label Nov 18, 2025
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Nov 18, 2025
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Nov 18, 2025
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Nov 18, 2025
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Nov 18, 2025
@erichare erichare enabled auto-merge November 18, 2025 00:55
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Nov 18, 2025
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Nov 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working community Pull Request from an external contributor lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants