-
Notifications
You must be signed in to change notification settings - Fork 8.2k
fix: Handle videos with no comments in YouTube Comments component #10633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- 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
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe Changes
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Pre-merge checks and finishing touchesImportant Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 error, 2 inconclusive)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this 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 tweakThe 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 giveninclude_metricssetting. The non-empty branch also safely injectsvideo_id/video_urlbefore 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
📒 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
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
erichare
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
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:
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
comments_datais empty before processingTesting
Tested with:
Type of Change
Summary by CodeRabbit
Release Notes