Skip to content

Code cleanup#74

Open
nlee3105 wants to merge 8 commits intoFNLCR-DMAP:devfrom
Saran-Nag:code-cleanup
Open

Code cleanup#74
nlee3105 wants to merge 8 commits intoFNLCR-DMAP:devfrom
Saran-Nag:code-cleanup

Conversation

@nlee3105
Copy link
Copy Markdown
Contributor

Summary

This PR cleans up legacy control-flow logic across the codebase by replacing inverted if-not patterns with standard if/else statements and removing the redundant flipper variable. These changes improve readability and maintainability without altering application behavior.

Changes

Replace if x is not False / inverted boolean logic with standard if x checks

Remove the flipper variable and simplify affected logic paths

Normalize conditional flow across server and data input modules

Testing

Manually tested core app flows to ensure no behavior changes

Verified plots, downloads, and dataset loading still function correctly

Reviewed Docker logs during testing; no errors or concerning logs observed.

Additional Context

This branch isolates code cleanup work originally included in core_refactor, separating it from feature and performance changes.

Contributors (with original commits linked):
@Saran-Nag : Formatting changes (link), effect_update_server.py, feat_vs_anno_server.py, features_server.py (link), nearest_neighbor_server.py, ripleyL_server.py, spatial_server.py, umap_server.py (link)

@NLee: anno_vs_anno_server.py, annotations_server.py, boxplot_server.py, data_input_server.py (link), Flipper variable removal

@risingmin : Flipper variable removal

Detailed Review (AI generated)

Logic Simplification (Multiple Files) Status: ✅ Improved

Change: Replaced flipper = shared['data_loaded'].get() followed by if flipper is not False: with direct usage if shared['data_loaded'].get():. Locations: umap_server.py, spatial_server.py, annotations_server.py, etc. Impact: drastically improves readability. The previous is not False check was unusually specific and likely a vestige of debugging.

  1. Truthiness Checks ( server/spatial_server.py ) Status: ⚠️ Verify

Change: if adata is not None: changed to if adata:.

Context: adata is an AnnData object.

Review: While AnnData objects generally support boolean evaluation (evaluating to True), relying on implicit truthiness for complex data structures can sometimes be risky if the library changes how bool or len is implemented (like Pandas, where it raises a ValueError).

Verdict: It is safe for now with AnnData, but sticking to if adata is not None: is generally more defensive for data containers.

  1. Download Handler Safety ( server/features_server.py ) Status: ✅ Excellent

Change: python

Old

if df is not None: # process

New

if df is None: return None else: # process

Impact: This avoids nested indentation and makes the "early exit" strategy clear. Crucially, it avoids accidentally doing if df: which would crash if df is a DataFrame.

  1. Formatting and Style Status: ✅ Good

Change: Wrapped long lines in ui.input_select and function calls (e.g., server/feat_vs_anno_server.py , server/spatial_server.py ).

Impact: Much better readability on standard screens and standardizes the codebase.

Comment on lines 266 to 270
if df is None:
return None
csv_string = df.to_csv(index=False)
csv_bytes = csv_string.encode("utf-8")
return csv_bytes, "text/csv"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess there is a missing "else:" or an indentation error?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved. Thanks for pointing that out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants