|
4 | 4 |
|
5 | 5 | def non_compliant(df: pd.DataFrame, df2: DataFrame):
|
6 | 6 |
|
7 |
| - df2.set_index("name").T.filter(like='joe', axis=0)[1].mean().head() # Noncompliant |
8 |
| -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
9 |
| - DataFrame().set_index("name").filter(like='joe', axis=0).groupby("team")["salary"].mean().head() # Noncompliant {{Refactor this long chain of instructions with pandas.pipe}} |
10 |
| -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
11 |
| - df.set_index("name").filter(like='joe', axis=0).groupby("team")["salary"].mean().head() # FN see SONARPY-1503 |
| 7 | + df2.set_index("name").T.filter(like='joe', axis=0)[1].add(10).mean().round().to_parquet() # Noncompliant |
| 8 | +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 9 | + DataFrame().set_index("name").filter(like='joe', axis=0).groupby("team")["salary"].add(10).mean().round().to_parquet() # Noncompliant {{Refactor this long chain of instructions with pandas.pipe}} |
| 10 | +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 11 | + df.set_index("name").filter(like='joe', axis=0).groupby("team")["salary"].add(10).mean().round().to_parquet() # FN see SONARPY-1503 |
12 | 12 |
|
13 |
| - df2.set_index("name").filter(like='joe', axis=0).groupby("team")["salary"]["test"].mean().head() # Noncompliant {{Refactor this long chain of instructions with pandas.pipe}} |
14 |
| -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
15 |
| - pd.read_csv("some_csv.csv").filter(like='joe', axis=0).groupby("team")["salary"]["test"].mean().head() # Noncompliant |
16 |
| -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 13 | + df2.set_index("name").filter(like='joe', axis=0).groupby("team")["salary"]["test"].add(10).mean().round().to_parquet() # Noncompliant {{Refactor this long chain of instructions with pandas.pipe}} |
| 14 | +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 15 | + pd.read_csv("some_csv.csv").filter(like='joe', axis=0).groupby("team")["salary"]["test"].add(10).mean().round().to_parquet() # Noncompliant |
| 16 | +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
17 | 17 |
|
18 | 18 |
|
19 | 19 | # Here we do not raise an issue only because we do not support subscription with Name
|
20 | 20 | # If support is added for such case we would encounter FPs when the subscription with Name is at the beginning of the chain
|
21 |
| - pd.read_csv("some_csv.csv").filter(like='joe', axis=0).groupby("team")["salary"]["test"].axes[1].unique() # FN |
| 21 | + pd.read_csv("some_csv.csv").filter(like='joe', axis=0).add(10).groupby("team")["salary"]["test"].axes[1].unique().to_json() # FN |
22 | 22 |
|
23 | 23 | # Here we should not raise an issue as the chain is done mainly on an Index object which does not have a pipe method
|
24 |
| - pd.read_csv("some_csv.csv").axes[1].join(pd.Index([4, 5, 6])).repeat([1,2]).drop_duplicates().insert(1, 42) |
| 24 | + pd.read_csv("some_csv.csv").axes[1].join(pd.Index([4, 5, 6])).T.repeat([1,2]).drop_duplicates().insert(1, 42).sort_values() |
25 | 25 |
|
26 | 26 | def compliant(df: pd.DataFrame, my_function, something, df2: DataFrame):
|
27 | 27 |
|
28 |
| - df2.set_index("name").T.filter(like='joe', axis=0)[1].mean() |
| 28 | + df2.set_index("name").T.filter(like='joe', axis=0)[1].add(10).mean().to_html() |
29 | 29 |
|
30 |
| - (df2.set_index("name").T.filter(like='joe', axis=0))[1].mean() |
| 30 | + (df2.set_index("name").T.filter(like='joe', axis=0))[1].add(10).mean().round().to_html() |
31 | 31 |
|
32 | 32 | df2.set_index("name").filter(like='joe', axis=0).mean().head()
|
33 | 33 |
|
34 | 34 | pd.read_csv("some_csv.csv").filter(like='joe', axis=0).groupby("team")["salary"]["test"].head()
|
35 | 35 |
|
36 | 36 | df.set_index("name").filter(like='joe', axis=0).groupby("team")["salary"].mean()
|
37 | 37 |
|
38 |
| - DataFrame().set_index("name").pipe(my_function).filter(like='joe', axis=0).groupby("team")["salary"].mean() |
| 38 | + DataFrame().set_index("name").pipe(my_function).filter(like='joe', axis=0).groupby("team")["salary"].add(10).round().mean().to_json() |
39 | 39 |
|
40 |
| - something.set_index("name").filter(like='joe', axis=0).groupby("team")["salary"].mean().head() |
| 40 | + something.set_index("name").filter(like='joe', axis=0).groupby("team")["salary"].add(10).round().mean().to_parquet() |
41 | 41 |
|
0 commit comments