@@ -259,6 +259,19 @@ def _is_persistent_array(array: blosc2.NDArray) -> bool:
259259 return array .urlpath is not None
260260
261261
262+ def _tmpdir_for_array (array : blosc2 .NDArray ) -> str | None :
263+ """Return a directory on the same filesystem as *array* for temp files.
264+
265+ When the array is backed by a file on disk we place temporaries next
266+ to it so that they share the same filesystem. This avoids hitting
267+ size limits on ``/tmp`` (commonly a tmpfs with only a few GB).
268+ For in-memory arrays we fall back to the system default (``None``).
269+ """
270+ if array .urlpath is not None :
271+ return str (Path (array .urlpath ).resolve ().parent )
272+ return None
273+
274+
262275def _load_store (array : blosc2 .NDArray ) -> dict :
263276 if _is_persistent_array (array ):
264277 key = _array_key (array )
@@ -3020,7 +3033,9 @@ def create_index(
30203033 )
30213034 full = None
30223035 if kind == "full" :
3023- with tempfile .TemporaryDirectory (prefix = "blosc2-index-ooc-" ) as tmpdir :
3036+ with tempfile .TemporaryDirectory (
3037+ prefix = "blosc2-index-ooc-" , dir = _tmpdir_for_array (array )
3038+ ) as tmpdir :
30243039 full = _build_full_descriptor_ooc (
30253040 array , target , token , kind , dtype , persistent , Path (tmpdir ), cparams
30263041 )
@@ -3123,7 +3138,9 @@ def create_expr_index(
31233138 )
31243139 full = None
31253140 if kind == "full" :
3126- with tempfile .TemporaryDirectory (prefix = "blosc2-index-ooc-" ) as tmpdir :
3141+ with tempfile .TemporaryDirectory (
3142+ prefix = "blosc2-index-ooc-" , dir = _tmpdir_for_array (array )
3143+ ) as tmpdir :
31273144 full = _build_full_descriptor_ooc (
31283145 array , target , token , kind , dtype , persistent , Path (tmpdir ), cparams
31293146 )
@@ -3776,7 +3793,7 @@ def compact_index(array: blosc2.NDArray, field: str | None = None, name: str | N
37763793 return _copy_descriptor (descriptor )
37773794
37783795 dtype = np .dtype (descriptor ["dtype" ])
3779- with tempfile .TemporaryDirectory (prefix = "blosc2-index-compact-" ) as tmpdir :
3796+ with tempfile .TemporaryDirectory (prefix = "blosc2-index-compact-" , dir = _tmpdir_for_array ( array ) ) as tmpdir :
37803797 workdir = Path (tmpdir )
37813798 runs = _full_compaction_runs (array , descriptor , workdir )
37823799 merge_buffer_items = max (int (array .chunks [0 ]), FULL_OOC_MERGE_BUFFER_ITEMS )
0 commit comments