Skip to content

Commit

Permalink
Merge branch 'main' into ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancescAlted authored Apr 1, 2024
2 parents 7f384e9 + 5b2918d commit e2475bb
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
python-version: ["3.10"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: 'recursive'

Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/cibuildwheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:

steps:
- name: Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: 'recursive'

Expand All @@ -73,7 +73,7 @@ jobs:
# CIBW_CONFIG_SETTINGS: "--build-option=-DDEACTIVATE_AVX512:BOOL=YES"

- name: Upload wheels
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
path: ./wheelhouse/*.whl

Expand All @@ -91,7 +91,7 @@ jobs:
arch: x86

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: 'recursive'

Expand All @@ -110,7 +110,7 @@ jobs:
python -m build --sdist
- name: Upload sdist package
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
path: dist/*.tar.gz

Expand All @@ -136,7 +136,7 @@ jobs:
# Only upload wheels when tagging (typically a release)
if: startsWith(github.event.ref, 'refs/tags')
steps:
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: artifact
path: dist
Expand Down
2 changes: 1 addition & 1 deletion blosc2/blosc2_ext.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1649,7 +1649,7 @@ cdef class vlmeta:
raise RuntimeError
res = {}
for i in range(rc):
res[names[i]] = unpackb(self.get_vlmeta(names[i]))
res[names[i]] = unpackb(self.get_vlmeta(names[i]), list_hook=decode_tuple)
return res


Expand Down
4 changes: 3 additions & 1 deletion blosc2/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ def compute_partition(nitems, parts, maxs, blocks=False):
"blocks should be smaller than chunks or shape in any dim!"
" If you do want this blocks, please specify a chunks too."
)
new_part = parts[i] * 2 if parts[i] * 2 <= maxs[i] else maxs[i]
new_part = min(parts[i] * 2, maxs[i])
if math.prod(parts) // parts[i] * new_part <= nitems:
parts[i] = new_part
nitems_new = math.prod(parts)
Expand Down Expand Up @@ -1208,6 +1208,8 @@ def compute_chunks_blocks(shape, chunks=None, blocks=None, dtype=np.uint8, **kwa
if len(blocks) != len(shape):
raise ValueError("blocks should have the same length than shape")
for i in range(len(blocks)):
if blocks[i] == 0:
raise ValueError("blocks cannot contain 0 dimension")
if blocks[i] > shape[i]:
raise ValueError("blocks cannot be greater than shape")
if chunks:
Expand Down
6 changes: 6 additions & 0 deletions tests/ndarray/test_empty.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,9 @@ def test_empty_minimal(shape, dtype):
def test_cparams_chunks_blocks(shape, cparams):
with pytest.raises(ValueError):
blosc2.empty(shape, cparams=cparams)


def test_zero_in_blockshape():
# Check for #165
with pytest.raises(ValueError):
blosc2.empty(shape=(1200,), chunks=(100,), blocks=(0,))
25 changes: 21 additions & 4 deletions tests/test_vlmeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def test_schunk(contiguous, urlpath, nbytes, cparams, dparams, nchunks):
assert nchunks_ == (i + 1)

add(schunk)
to_dict(schunk)
iter(schunk)
delete(schunk)
clear(schunk)
Expand All @@ -68,12 +69,26 @@ def add(schunk):
schunk.vlmeta["vlmeta1"] = b"val1"
schunk.vlmeta["vlmeta2"] = "val2"
schunk.vlmeta["vlmeta3"] = {b"lorem": 4231}
schunk.vlmeta["vlmeta4"] = [1, 2, 3]
schunk.vlmeta["vlmeta5"] = (1, 2, 3)

assert schunk.vlmeta["vlmeta1"] == b"val1"
assert schunk.vlmeta["vlmeta2"] == "val2"
assert schunk.vlmeta["vlmeta3"] == {b"lorem": 4231}
assert schunk.vlmeta["vlmeta4"] == [1, 2, 3]
assert schunk.vlmeta["vlmeta5"] == (1, 2, 3)
assert "vlmeta1" in schunk.vlmeta
assert len(schunk.vlmeta) == 3
assert len(schunk.vlmeta) == 5


def to_dict(schunk):
assert schunk.vlmeta.to_dict() == {
b"vlmeta1": b"val1",
b"vlmeta2": "val2",
b"vlmeta3": {b"lorem": 4231},
b"vlmeta4": [1, 2, 3],
b"vlmeta5": (1, 2, 3),
}


def delete(schunk):
Expand All @@ -83,13 +98,15 @@ def delete(schunk):
assert "vlmeta2" not in schunk.vlmeta
assert schunk.vlmeta["vlmeta1"] == b"val1"
assert schunk.vlmeta["vlmeta3"] == {b"lorem": 4231}
assert schunk.vlmeta["vlmeta4"] == [1, 2, 3]
assert schunk.vlmeta["vlmeta5"] == (1, 2, 3)
with pytest.raises(KeyError):
schunk.vlmeta["vlmeta2"]
assert len(schunk.vlmeta) == 2
assert len(schunk.vlmeta) == 4


def iter(schunk):
keys = ["vlmeta1", "vlmeta2", "vlmeta3"]
keys = ["vlmeta1", "vlmeta2", "vlmeta3", "vlmeta4", "vlmeta5"]
for i, vlmeta in enumerate(schunk.vlmeta):
assert vlmeta == keys[i]

Expand All @@ -98,7 +115,7 @@ def clear(schunk):
nparray = np.arange(start=0, stop=2)
schunk.vlmeta["vlmeta2"] = nparray.tobytes()
assert schunk.vlmeta["vlmeta2"] == nparray.tobytes()
assert schunk.vlmeta.__len__() == 3
assert schunk.vlmeta.__len__() == 5

schunk.vlmeta.clear()
assert schunk.vlmeta.__len__() == 0

0 comments on commit e2475bb

Please sign in to comment.