|
1 | 1 | """Convenience functions for storing and loading data."""
|
2 | 2 | import io
|
3 | 3 | import itertools
|
| 4 | +import os |
4 | 5 | import re
|
5 | 6 | from collections.abc import Mapping
|
6 | 7 |
|
@@ -100,6 +101,10 @@ def open(store=None, mode='a', **kwargs):
|
100 | 101 | raise PathNotFoundError(path)
|
101 | 102 |
|
102 | 103 |
|
| 104 | +def _might_close(path): |
| 105 | + return isinstance(path, (str, os.PathLike)) |
| 106 | + |
| 107 | + |
103 | 108 | def save_array(store, arr, **kwargs):
|
104 | 109 | """Convenience function to save a NumPy array to the local file system, following a
|
105 | 110 | similar API to the NumPy save() function.
|
@@ -131,7 +136,7 @@ def save_array(store, arr, **kwargs):
|
131 | 136 | array([ 0, 1, 2, ..., 9997, 9998, 9999])
|
132 | 137 |
|
133 | 138 | """
|
134 |
| - may_need_closing = isinstance(store, str) |
| 139 | + may_need_closing = _might_close(store) |
135 | 140 | store = normalize_store_arg(store, clobber=True)
|
136 | 141 | try:
|
137 | 142 | _create_array(arr, store=store, overwrite=True, **kwargs)
|
@@ -202,7 +207,7 @@ def save_group(store, *args, **kwargs):
|
202 | 207 | if len(args) == 0 and len(kwargs) == 0:
|
203 | 208 | raise ValueError('at least one array must be provided')
|
204 | 209 | # handle polymorphic store arg
|
205 |
| - may_need_closing = isinstance(store, str) |
| 210 | + may_need_closing = _might_close(store) |
206 | 211 | store = normalize_store_arg(store, clobber=True)
|
207 | 212 | try:
|
208 | 213 | grp = _create_group(store, overwrite=True)
|
|
0 commit comments