Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tests so they work on mac; add disclaimer about numpy versions #4

Merged
merged 24 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,19 @@ jobs:

strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
numpy-version: ["1.24.2", "1.26.4", "2.0.0"]
exclude:
- python-version: "3.8"
numpy-version: "2.0.0"
- python-version: "3.8"
numpy-version: "1.26.4"
- python-version: "3.12"
numpy-version: "1.24.2"
- os: windows-latest
numpy-version: "2.0.0"


steps:
- uses: actions/checkout@v3
Expand All @@ -21,6 +32,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install numpy==${{ matrix.numpy-version }}
pip install -r requirements.txt
- name: Test with pytest
run: |
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def f(large_argument, not_json_argument, transient_flag):

The dictionary has keys that correspond to each of the arguments, and the values are applied to them before placing them in the key. Here, `stable_hash` can be used to hash the json stringification of the value, saving disk space but making recovering the value impossible if you want to do that later. Additionally, `str` can be used to stringify objects that you are convinced have stable `str` representations but cannot be represented in json. Finally, the flag argument is ignored in the JSON representation, this is useful for verbosity flags, etc., that don't affect the output.

**Extremely important note**: If you use `stable_hash`, it is only guaranteed to be stable for the same major version of `numpy` (numpy `1.*.*` vs `2.*.*`) and the same operating system. On Ubuntu it does appear to be stable across versions of `numpy`, but this is not true on Mac OS.

## Aliasing

Permacache uses the underlying function signature to construct the key. For example, for the function
Expand Down
13 changes: 11 additions & 2 deletions tests/stringify_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,26 @@

from permacache import stable_hash, stringify

NUMPY_VERSION = np.version.version.split(".", maxsplit=1)[0]


class StringifyTest(unittest.TestCase):
data = np.random.RandomState(0).randn(1000)
slow_hash = {
"linux": "16469cff96525e3e190758d793e61f9d798cb87617787bc1312cf7a8b59aa4b2",
"win32": "faaa45dfa377870db4d547ca91187566b6b74983adaf16241a80ef96af592285",
"darwin": "97d8947421010821dd8f3f7046ef0eccd5c27602c7505a5749c1090a0fe7435b",
"darwin": {
"1": "97d8947421010821dd8f3f7046ef0eccd5c27602c7505a5749c1090a0fe7435b",
"2": "f80b352d29bedc2147f6d5a3623226c7f350bbab1f743ffe0a257132c5a60597",
}[NUMPY_VERSION],
}[sys.platform]
fast_hash = {
"linux": "c97fda7d817a32aad65ce77f5043a51410c5893e6bab8e746a23f68c8e483774",
"win32": "387b1ef12b70d4df0984846b753fbcceb1b7d079256e75479810b6a15d668b70",
"darwin": "76ce19673caf9532d68730c7f83bfe8e6f521cc001c2d43373f9c4f33c925037",
"darwin": {
"1": "76ce19673caf9532d68730c7f83bfe8e6f521cc001c2d43373f9c4f33c925037",
"2": "a0128e05b5d5ceab4d1b5716c5ce3339b25f3ef6a1208383e6c99afdc2b519c1",
}[NUMPY_VERSION],
}[sys.platform]

def test_stringify_json(self):
Expand All @@ -39,6 +47,7 @@ class X:
)

def test_stringify_numpy(self):
print(self.data.tobytes())
self.assertEqual(
self.slow_hash,
stable_hash(self.data, fast_bytes=False),
Expand Down
Loading