Skip to content

Commit c953dd2

Browse files
committed
fixed one code smell and updated report.md
1 parent 4d89314 commit c953dd2

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

courseProjectDocs/static-analysis/report.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,52 @@ def validate_fillna_kwargs(value, method, validate_scalar_dict_value: bool = Tru
100100

101101
**Rationale:** Module-level imports are executed once at module load time rather than every function call, improving performance. It also makes dependencies more visible and follows PEP 8 conventions.
102102

103-
---
103+
---
104+
105+
106+
### Fix #3: Nested If Statements (SIM102)
107+
**Assigned to:** Mallikarjuna
108+
**Location:** Lines 471-472 in `pandas/util/_validators.py`
109+
**Issue:** Unnecessary nested if statements can be combined with `and`
110+
111+
**Before:**
112+
```python
113+
def check_dtype_backend(dtype_backend) -> None:
114+
if dtype_backend is not lib.no_default:
115+
if dtype_backend not in ["numpy_nullable", "pyarrow"]:
116+
raise ValueError(
117+
f"dtype_backend {dtype_backend} is invalid, only 'numpy_nullable' and "
118+
f"'pyarrow' are allowed.",
119+
)
120+
```
121+
122+
**After:**
123+
```python
124+
def check_dtype_backend(dtype_backend) -> None:
125+
if dtype_backend is not lib.no_default and dtype_backend not in ["numpy_nullable", "pyarrow"]:
126+
raise ValueError(
127+
f"dtype_backend {dtype_backend} is invalid, only 'numpy_nullable' and "
128+
f"'pyarrow' are allowed.",
129+
)
130+
```
131+
132+
**Rationale:** Combining related conditions into a single if statement reduces nesting depth, improves readability, and makes the code more concise without losing clarity.
133+
134+
---
135+
136+
## Group Contributions
137+
138+
**Sandeep Ramavath:**
139+
- Identified and fixed EM102 code smell (f-string in exception)
140+
- Refactored exception handling to use variable assignment
141+
- Impact: Improved exception handling best practices
142+
143+
**Nithikesh Bobbili:**
144+
- Identified and fixed PLC0415 code smell (import location)
145+
- Moved import statement to module level
146+
- Impact: Better performance and code organization
147+
148+
**Mallikarjuna:**
149+
- Identified and fixed SIM102 code smell (nested if statements)
150+
- Simplified conditional logic by combining conditions
151+
- Impact: Reduced code complexity and improved readability
Binary file not shown.

pandas/util/_validators.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,8 @@ def validate_insert_loc(loc: int, length: int) -> int:
467467

468468

469469
def check_dtype_backend(dtype_backend) -> None:
470-
if dtype_backend is not lib.no_default:
471-
if dtype_backend not in ["numpy_nullable", "pyarrow"]:
472-
raise ValueError(
470+
if dtype_backend is not lib.no_default and dtype_backend not in ["numpy_nullable", "pyarrow"]:
471+
raise ValueError(
473472
f"dtype_backend {dtype_backend} is invalid, only 'numpy_nullable' and "
474473
f"'pyarrow' are allowed.",
475474
)

0 commit comments

Comments
 (0)