Add problem to company mapping - #1
Conversation
📝 WalkthroughWalkthroughA new Jupyter notebook aggregates LeetCode problem data from company-specific CSV files, combining multiple sources into a single DataFrame, grouping problems by title, and outputting a JSON mapping of each problem title to its associated companies as a sorted unique list. ChangesLeetCode Problem Aggregation Pipeline
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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.
Actionable comments posted: 2
🧹 Nitpick comments (1)
script.ipynb (1)
30-137: ⚡ Quick winRemove stored notebook outputs before commit.
Committed HTML/table outputs make diffs large and noisy and increase merge churn for regenerated data pipelines.
Also applies to: 187-255
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@script.ipynb` around lines 30 - 137, The notebook contains committed cell outputs (the "outputs" arrays and non-null "execution_count" values) which should be removed; open the notebook (script.ipynb), clear all cell outputs and set execution_count to null for each cell (remove any HTML/table blobs under the "outputs" field), then recommit only the source cells. To prevent future commits, add a notebook-cleaning hook (e.g., install/enable nbstripout or add a .gitattributes rule to filter ipynb outputs) and update the repo docs so contributors run the hook before committing.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@script.ipynb`:
- Around line 258-262: The current aggregation builds the mapping keyed by Title
(using combined.groupby('Title')['company']...), but the PR requires an
ID→company mapping; change the grouping and key to use the unique ID field
instead of Title (e.g., use combined.groupby('ID',
as_index=False)['company'].agg(...)) and produce the output mapping keyed by ID
(apply same fix for the other occurrence around the 281-284 block), ensuring the
aggregated values remain the sorted unique company lists.
- Around line 160-171: The code calls pd.concat(df_list, ignore_index=True)
without guarding against df_list being empty; add an explicit check before that
line to handle the empty-case (e.g., if not df_list: raise a clear ValueError or
create an empty DataFrame) so the failure is actionable; update the logic around
the df_list accumulation and the combined assignment (referencing df_list and
combined) to either produce an empty DataFrame with the expected columns or
raise a descriptive error like "No '5. All.csv' files found, nothing to
concatenate".
---
Nitpick comments:
In `@script.ipynb`:
- Around line 30-137: The notebook contains committed cell outputs (the
"outputs" arrays and non-null "execution_count" values) which should be removed;
open the notebook (script.ipynb), clear all cell outputs and set execution_count
to null for each cell (remove any HTML/table blobs under the "outputs" field),
then recommit only the source cells. To prevent future commits, add a
notebook-cleaning hook (e.g., install/enable nbstripout or add a .gitattributes
rule to filter ipynb outputs) and update the repo docs so contributors run the
hook before committing.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 69f6c66e-b780-4cd5-9790-0dc8f185cbf1
📒 Files selected for processing (2)
problem_company_mapping.jsonscript.ipynb
| "for folder in root.iterdir():\n", | ||
| "\n", | ||
| " csv = folder / \"5. All.csv\"\n", | ||
| "\n", | ||
| " if not csv.exists():\n", | ||
| " continue\n", | ||
| "\n", | ||
| " df = pd.read_csv(csv, usecols=['Title'])\n", | ||
| " df['company'] = folder.name\n", | ||
| " df_list.append(df)\n", | ||
| "\n", | ||
| "combined = pd.concat(df_list, ignore_index=True)\n" |
There was a problem hiding this comment.
Guard pd.concat against an empty source list.
If no 5. All.csv files are discovered, Line [171] raises ValueError: No objects to concatenate. Add an explicit check so failures are clear and actionable.
Proposed fix
df_list = []
for folder in root.iterdir():
csv = folder / "5. All.csv"
if not csv.exists():
continue
df = pd.read_csv(csv, usecols=['Title'])
df['company'] = folder.name
df_list.append(df)
+if not df_list:
+ raise FileNotFoundError(f"No '5. All.csv' files found under {root}")
+
combined = pd.concat(df_list, ignore_index=True)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| "for folder in root.iterdir():\n", | |
| "\n", | |
| " csv = folder / \"5. All.csv\"\n", | |
| "\n", | |
| " if not csv.exists():\n", | |
| " continue\n", | |
| "\n", | |
| " df = pd.read_csv(csv, usecols=['Title'])\n", | |
| " df['company'] = folder.name\n", | |
| " df_list.append(df)\n", | |
| "\n", | |
| "combined = pd.concat(df_list, ignore_index=True)\n" | |
| for folder in root.iterdir(): | |
| csv = folder / "5. All.csv" | |
| if not csv.exists(): | |
| continue | |
| df = pd.read_csv(csv, usecols=['Title']) | |
| df['company'] = folder.name | |
| df_list.append(df) | |
| if not df_list: | |
| raise FileNotFoundError(f"No '5. All.csv' files found under {root}") | |
| combined = pd.concat(df_list, ignore_index=True) |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@script.ipynb` around lines 160 - 171, The code calls pd.concat(df_list,
ignore_index=True) without guarding against df_list being empty; add an explicit
check before that line to handle the empty-case (e.g., if not df_list: raise a
clear ValueError or create an empty DataFrame) so the failure is actionable;
update the logic around the df_list accumulation and the combined assignment
(referencing df_list and combined) to either produce an empty DataFrame with the
expected columns or raise a descriptive error like "No '5. All.csv' files found,
nothing to concatenate".
| "summary = (\n", | ||
| " combined\n", | ||
| " .groupby('Title', as_index=False)['company']\n", | ||
| " .agg(lambda values: sorted(set(values)))\n", | ||
| ")\n", |
There was a problem hiding this comment.
Output schema is Title-based, not ID-based as stated in the PR objective.
The generated mapping keys by Title, but the PR objective describes an ID → company contract. This can break downstream consumers expecting stable numeric IDs.
Also applies to: 281-284
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@script.ipynb` around lines 258 - 262, The current aggregation builds the
mapping keyed by Title (using combined.groupby('Title')['company']...), but the
PR requires an ID→company mapping; change the grouping and key to use the unique
ID field instead of Title (e.g., use combined.groupby('ID',
as_index=False)['company'].agg(...)) and produce the output mapping keyed by ID
(apply same fix for the other occurrence around the 281-284 block), ensuring the
aggregated values remain the sorted unique company lists.
This PR adds a
problem_company_mapping.json.Sample structure:
This data can be useful for browser extensions that inject company-wise tags for LeetCode problems. (I'm building one currently). Centralizing the data avoids each consumer maintaining separate copies.
I've included the python script used to generate it.
If it makes sense for the repo, I can set up a GitHub Action to auto-update the JSON.