SML Small (Python Pandas methods)
Project description
SML-PYTHON-SMALL
Statistical Methods Library for Python Pandas methods used in the Statistical Production Platform (SPP).
This library contains pandas statistical methods that are only suitable for use on small datasets which can safely be processed in-memory.
For further information about the methods contained in this module see the method specifications
For user documentation and example data relating to the methods in this module see the supporting information
Automated testing
In order to ensure code quality, there is a manual test script provided run_py_tools.sh which will run linting, code formatting checks, and the pytest suite.
It is often easy to forget to check code formatting before pushing to the remote repository, so there is the option of running the testing script automatically by using the git hook pre-push. This means that when git push is run, the test script will be run first, and will abort the push if any of the tests fail.
Git hooks cannot be pushed to the remote repository so if you would like this script to be run automatically you will need to follow these steps:
- Check that the .git directory is present in your repository by running ls -a in the terminal
- Run cd .git/hooks and open the file marked pre-push.sample in a code editor
- Replace the content of this file with the following code:
#!/bin/sh
GREEN='\033[1;32m'
RED='\033[1;31m'
YELLOW='\033[1;33m'
NC='\033[0m'
git stash clear # in case there is nothing to stash,
# then the stash needs to be empty, else previously
# stashed changes will be incorrectly restored
git stash
testing_script="./run_py_tools.sh"
if "$testing_script"; then
echo "${GREEN}./run_py_tools script passes, proceeding with push...${NC}"
git add . # commit any changes made by the pytools script
git commit -m "run_py_tools auto-formatting"
git stash apply
echo "${YELLOW}NOTE: If any commits were made by the auto-formatting tool, then they will not be automatically pushed. You will need to run git push again (or git push --no-verify if you don't want to run the test suite again).${NC}"
# uncomment the line below if you would like the commits to be pushed automatically.
# git push --no-verify # NOTE: this will cause git to throw an error, but the functionality is correct.
exit 0
else
echo "${RED}./run_py_tools script fails, push aborted.${NC}"
git checkout . # revert any changes made by the pytools script
git stash apply
exit 1
fi
- Save the file and rename it to pre-push (i.e. remove the .sample suffix from the filename)
- Run cd ../.. to change the current working directory back to the root directory of the sml-python-small repository
- Open a poetry shell and run git push to check if the testing tools work (it doesn't matter if there is nothing to push, the pre-push hook will still run).
- After all of the tests have run, you should see something like this:
================================================================================= 443 passed in 12.58s ==================================================================================
Test Results:
black --check --diff sml_small tests : Success
flake8 sml_small tests : Success
isort --check-only . : Success
bandit -c pyproject.toml -r . : Success
./run_py_tools script passes, proceeding with push...
Everything up-to-date
- If any of the linting tests or pytest files fail then the push will be aborted.
Troubleshooting
- In order to push, you need to run the git push command in a poetry shell, otherwise all of the tests will fail.
- You also need to ensure that your current working directory in the terminal is within the sml-python-small repository.
- While the script is running, any non-committed changes will be stashed. This means that any work after the commit has been made may seem to disappear for a moment during the tests. After the file has finished running, the stashed changes will be automatically restored. This is to ensure that the tests are being run on the code within the commits, rather than any non-committed changes.
- If for any reason the script exits unexpectedly, you can restore the stashed changes manually by running the following command:
git stash apply
- If any changes are made by the auto-formatting tool, then these will automatically be committed, but it is not possible to automatically push these changes. You can check by running git log. If the most recent commit is titled 'run_py_tools auto-formatting', then you will need to run git push again (or git push --no-verify if you don't want to run the test suite again).
- If you would like these commits to be pushed automatically, then you can uncomment the git push --no-verify line in the code. This is optional, since pushing during the pre-push hook will cause git to throw an error, however the functionality is correct.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file sml_small-1.2.1.tar.gz
.
File metadata
- Download URL: sml_small-1.2.1.tar.gz
- Upload date:
- Size: 40.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9913bc92247c7d7825c879aea2a6960dced76af086f7da237499f8e0698cd857 |
|
MD5 | a4b4cd351a15205cf7d366890432278f |
|
BLAKE2b-256 | 9a563fad6e758691102839d4f6693f94747e3100d4824cf51e2f0ac796c276e1 |
File details
Details for the file sml_small-1.2.1-py3-none-any.whl
.
File metadata
- Download URL: sml_small-1.2.1-py3-none-any.whl
- Upload date:
- Size: 43.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b2b91d6ba28cc01c3316014ccfbf3846e5639f44dab89fa85c15a4cae2ed5f4 |
|
MD5 | a5e85aa48d76057a34f56eef38fd02b6 |
|
BLAKE2b-256 | f710a34d57ef3895175814e58e531963449c8142875064ff4ad93387a2dc5297 |