mirror of
https://github.com/NicolasBohn/NexQuant.git
synced 2026-08-08 20:47:44 +00:00
fix(auto-fixer): strip spurious .reset_index() after .transform() calls
LLM sometimes copies the .reset_index(level=N, drop=True) suffix from groupby().rolling().method() patterns and adds it after .transform(), but transform() already preserves the original index. The extra reset_index() drops an index level and causes ValueError: 'cannot reindex on an axis with duplicate labels' or shape mismatch on assignment. Detect: any line containing both .transform( and .reset_index(level=..., drop=True) Fix: strip the .reset_index() suffix from those lines. Adds 1 new test (test_transform_reset_index_stripped) — total 30 tests. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -197,6 +197,13 @@ class TestGroupbyApplyToTransform:
|
||||
assert "lambda x: x.cumsum()" in result
|
||||
assert ".transform(" in result
|
||||
|
||||
def test_transform_reset_index_stripped(self, fixer):
|
||||
# .transform() already preserves index — .reset_index() after it is wrong
|
||||
code = "df['v'] = df.groupby(level=1)['x'].transform(lambda x: x.rolling(20).mean()).reset_index(level=0, drop=True)"
|
||||
result = fixer.fix(code)
|
||||
assert ".reset_index(level=0, drop=True)" not in result
|
||||
assert ".transform(" in result
|
||||
|
||||
|
||||
class TestRollingDdof:
|
||||
def test_removes_ddof_from_rolling_args(self, fixer):
|
||||
|
||||
Reference in New Issue
Block a user