diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 8e1e7a4..907cd3d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -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 @@ -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: | diff --git a/README.md b/README.md index 9e9e8b1..b8dcd43 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/tests/stringify_test.py b/tests/stringify_test.py index 273a5d0..3d90371 100644 --- a/tests/stringify_test.py +++ b/tests/stringify_test.py @@ -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): @@ -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),