Skip to content

Cleaning Formatting in Demag Gui#846

Merged
Swanson-Hysell merged 5 commits into
PmagPy:masterfrom
apivarunas:cleaning-demag-gui
Apr 24, 2026
Merged

Cleaning Formatting in Demag Gui#846
Swanson-Hysell merged 5 commits into
PmagPy:masterfrom
apivarunas:cleaning-demag-gui

Conversation

@apivarunas

Copy link
Copy Markdown
Collaborator

Using recommendations from the ruff linter and formatter extension in VS Code, cleaning various issues in Demag Gui. Highlights include:

  1. Partially cleaning and re-organizing imports, removing unused imports, cleaning some duplicates.

  2. Fixing style of equality comparisons (i.e., == to is, etc.), type comparisons.

Went from 258 "problems" to 125. Most of what is left is variable assignments, which are a little touchy, bare except statements, and some import confusion (mostly from star imports, I think). But, a little at a time and that done well.

@Swanson-Hysell

Copy link
Copy Markdown
Member

Reviewed the diff and did a smoke test opening a working data directory and
stepping through the GUI — everything behaves as expected.

The changes are carefully largely mechanical (== Noneis None,
type(x) == Ytype(x) is Y, == True → truthy, unused import removal,
DataFrame/Seriespd.DataFrame/pd.Series) and I verified each of
the removed imports is no longer referenced in the file. Two changes are
arguably latent bug fixes: scipy.meanmean (scipy isn't actually
imported at the top level and scipy.mean was removed in SciPy 2.0), and
math.isnannp.isnan (math isn't imported either).

The only behavioral tightening is the bare except:except FileNotFoundError:
changes in get_data_info and update_pmag_tables. My smoke test used a
complete working directory so it didn't exercise those paths — worth noting
that read_magic_file and pmag.magic_read both handle missing files
internally and return [] rather than raising, so the except FileNotFoundError:
branches will effectively never fire regardless. If anything, it's better
to let unexpected exceptions propagate than silently swallow them, so the
tightening is a net positive.

A couple of small follow-up opportunities spotted while reading:

  • Lines 3636 and 3652 have type(tmin) is str or type(tmin) is str and tmin != ''
    the two conditions are identical, so the whole expression reduces to
    type(tmin) is str.
  • The file has both import numpy as np and from numpy import vstack, sqrt, arange, array, mean, nan, which invites inconsistent np.array vs
    array usage. Worth consolidating to one style in a separate PR.
  • A leftover #DEBUG print in add_fit (line 2586) that probably makes sense to look into and clean-up.

@Swanson-Hysell Swanson-Hysell merged commit 4e969fe into PmagPy:master Apr 24, 2026
2 checks passed
@apivarunas apivarunas deleted the cleaning-demag-gui branch May 6, 2026 04:37
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.

2 participants