Repository navigation
Modernise packaging, fix path and overwrite handling, add linting and tests - #1
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Brings the package up to date after a long gap, and fixes several defects found along the way.
Packaging
pytestwas listed ininstall_requires, sopip install weighslidepulled a test framework,pluggy,iniconfigandpygmentsinto the user's environment. It is now an optionaldevdependency.openpyxlwas the mirror image:run_weighslidealways writes an xlsx file, which pandas delegates to openpyxl, but pandas does not install it. It is now declared.setup.pyandsetup.cfgare replaced bypyproject.toml, and the package gains aweighslideconsole script. Version 0.2.5 to 0.3.0.Defects fixed
weighslide -i <file>raisedAttributeErrorbefore reading any data, because the code calledinfile.nameon a string. The string-path form documented in the README failed the same way.-o/--overwritebut never passed it on, so a rerun always raisedFileExistsError.import weighslide.Behaviour is otherwise unchanged. The four return values of
calculate_weighted_windowswere compared against output captured from the previous code across six window and statistic combinations, and are identical.Supported versions
requires-pythonis 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: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.