Skip to main content

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

sml_small-1.2.3.tar.gz (40.2 kB view details)

Uploaded Source

Built Distribution

sml_small-1.2.3-py3-none-any.whl (43.1 kB view details)

Uploaded Python 3

File details

Details for the file sml_small-1.2.3.tar.gz.

File metadata

  • Download URL: sml_small-1.2.3.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

Hashes for sml_small-1.2.3.tar.gz
Algorithm Hash digest
SHA256 a829375bea8512b2c0053cd9a06a0108f8a9a1e5f881543abe057fdf2ac2ff86
MD5 b1ce3968257e037f2d103d3d6d0075e9
BLAKE2b-256 bcd25eacbb0ce5cc1f10ad01e5d33433fe8d26f94a93b0910e95e3f887621f8f

See more details on using hashes here.

File details

Details for the file sml_small-1.2.3-py3-none-any.whl.

File metadata

  • Download URL: sml_small-1.2.3-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

Hashes for sml_small-1.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 04561771f041431d9782ac76f504fe253a2007df66247bbcd3c8a91636e04f74
MD5 77ae88a4d3d837a4dc9395c9530050a0
BLAKE2b-256 f61cf8b7537404141934620a7df0125474e316bf3e432788dec63c1146e94d1a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page