Skip to content

Modernise packaging, fix path and overwrite handling, add linting and tests - #1

Merged
teese merged 6 commits into
masterfrom
modernise-packaging-and-linting
Aug 31, 2026
Merged

teese merged 6 commits into
masterfrom
modernise-packaging-and-linting

Conversation

@teese

@teese teese commented Aug 31, 2026

Copy link
Copy Markdown
Owner

Brings the package up to date after a long gap, and fixes several defects found along the way.

Packaging

pytest was listed in install_requires, so pip install weighslide pulled a test framework, pluggy, iniconfig and pygments into the user's environment. It is now an optional dev dependency.

openpyxl was the mirror image: run_weighslide always writes an xlsx file, which pandas delegates to openpyxl, but pandas does not install it. It is now declared.

setup.py and setup.cfg are replaced by pyproject.toml, and the package gains a weighslide console script. Version 0.2.5 to 0.3.0.

Defects fixed

  • weighslide -i <file> raised AttributeError before reading any data, because the code called infile.name on a string. The string-path form documented in the README failed the same way.
  • The command line parsed -o/--overwrite but never passed it on, so a rerun always raised FileExistsError.
  • Plotted lines carried no labels, so every output figure had an empty legend and emitted a warning.
  • Slicing mixed label and positional indexing, giving wrong results for any input whose index was not a zero-based range.
  • The argument parser was built at module scope, so it ran on every import weighslide.
  • Deprecated pandas calls that warn under pandas 2 and later.
  • Slice frames were concatenated inside the loop, which was quadratic in input length.

Behaviour is otherwise unchanged. The four return values of calculate_weighted_windows were compared against output captured from the previous code across six window and statistic combinations, and are identical.

Supported versions

requires-python is 3.9 and the dependency lower bounds are the oldest versions the suite is actually run against, rather than estimates. The suite passes at both ends of the range:

oldest tested newest tested
python 3.9 3.13
pandas 1.2.5 3.0.5
numpy 1.20.3 2.5.2
matplotlib 3.4.3 3.11.1

Tooling and tests

pre-commit runs black, ruff and mypy; CI runs the same hooks plus the suite on Linux and Windows. The previous single test asserted only that four files existed; the suite now covers the worked example from the README, window parsing, input validation, all three statistics, index handling, csv and excel input, overwrite behaviour and the command line, with regression tests for the defects above.

The README's contact image pointed at a branch of another repository, and has been removed in favour of the issue tracker.

teese added 6 commits August 31, 2026 12:22
run_weighslide read the file extension via infile.name, which only works
when a Path is passed. The command line passed a normalised string, so
`weighslide -i <file>` raised AttributeError before reading any data, as
did the string-path form documented in the README. The path is now
converted to a Path on entry, so both call styles behave the same.

The command line parsed -o/--overwrite but never passed it on, so a
second run against the same input raised FileExistsError whatever the
flag was set to.

The plotted lines carried no labels, so the legend was drawn empty and
matplotlib warned on every run.

Slicing indexed the padded series by label while treating the index
value as a position, which produced wrong slices for any input whose
index was not a zero-based range. Slicing is now positional throughout,
and the caller's index is restored on the returned series.

Also moves the argument parser out of module scope, where it was built
on every import, into build_parser() and main(); replaces the inplace
replace() and positional Series assignment that are deprecated in
pandas 2 and later; and collects the slice frames in lists rather than
concatenating inside the loop, which was quadratic in input length.
Declares pytest as an optional dev dependency instead of a runtime one.
It was listed in install_requires, so installing weighslide pulled a
test framework and its dependencies into the user's environment.

Adds openpyxl as a runtime dependency. run_weighslide always writes an
xlsx output file, which pandas delegates to openpyxl, but pandas does
not install openpyxl itself.

Adds a weighslide console script. The previous instruction to run
`python weighslide.py` does not work for an installed package.

The dependency lower bounds are the oldest versions the test suite has
been run against rather than estimates. requires-python is set to 3.9,
the oldest version the code runs on; declaring it lets pip offer older
interpreters the previous release instead of failing on install.

Version 0.2.5 to 0.3.0, for the changed dependency contract and the new
console script.
Runs black, ruff and mypy, at the hook revisions already in use across
the other repositories. CI runs the same hooks so that an unformatted
commit is caught before merge, then runs the test suite on Linux and
Windows across python 3.9, 3.12 and 3.13. That matrix spans both
pandas 1.x and pandas 3.x, which behave differently for several of the
calls this package makes.
The previous test asserted only that four output files had been created,
so nothing checked the values the package produces.

The new tests cover the worked example carried in the README and the
docstring, window parsing including ignored positions, every input
validation path, all three statistics, index handling, csv and excel
input, overwrite behaviour and the command line interface. The path
handling and overwrite defects fixed earlier on this branch have
regression tests, and one test asserts that a run raises no deprecation
warnings, so that the drift that had accumulated here does not recur
unnoticed.
The installation section named python 3.5 and `python setup.py install`,
and every usage example invoked `python weighslide.py`, none of which
apply to an installed package. Documents the console script, the output
files each run produces, the range of python and dependency versions the
test suite is run against, and the development setup.

Removes the contact image, which pointed at a branch of a different
repository and would break if that branch were ever deleted, and points
the contribute section at this repository's issue tracker instead.
pd.Series.replace downcasts an object column, which is deprecated in
pandas 2.2 and 2.3 and raises a FutureWarning there. The list form of
the window went through that call, so any caller passing a list rather
than a string produced the warning on those versions. The window is now
built with plain numpy, which has no equivalent deprecation and drops a
pandas round trip from the conversion.

The test that asserts a run raises no deprecation warnings only
exercised the string form, so it did not cover the affected branch. It
now runs over both forms.
@teese
teese merged commit 7a8628c into master Aug 31, 2026
14 checks passed
@teese
teese deleted the modernise-packaging-and-linting branch August 31, 2026 10:38
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.

1 participant