MCPcopy Index your code
hub / github.com/pydata/xarray / __init__

Method __init__

xarray/backends/scipy_.py:222–278  ·  view source on GitHub ↗
(
        self,
        filename_or_obj: T_PathFileOrDataStore,
        mode: Literal["r", "w", "a"] = "r",
        format: str | None = None,
        group: str | None = None,
        mmap: bool | None = None,
        lock: Lock | Literal[False] | None = None,
    )

Source from the content-addressed store, hash-verified

220 _manager: FileManager[scipy.io.netcdf_file]
221
222 def __init__(
223 self,
224 filename_or_obj: T_PathFileOrDataStore,
225 mode: Literal["r", "w", "a"] = "r",
226 format: str | None = None,
227 group: str | None = None,
228 mmap: bool | None = None,
229 lock: Lock | Literal[False] | None = None,
230 ) -> None:
231 if group is not None:
232 raise ValueError("cannot save to a group with the scipy.io.netcdf backend")
233
234 version: Literal[1, 2]
235 if format is None or format == "NETCDF3_64BIT":
236 version = 2
237 elif format == "NETCDF3_CLASSIC":
238 version = 1
239 else:
240 raise ValueError(f"invalid format for scipy.io.netcdf backend: {format!r}")
241
242 if lock is None and mode != "r" and isinstance(filename_or_obj, str):
243 lock = get_write_lock(filename_or_obj)
244
245 self.lock = ensure_lock(lock)
246
247 if isinstance(filename_or_obj, BytesIOProxy):
248 source = filename_or_obj
249 filename_or_obj = io.BytesIO()
250 source.getvalue = filename_or_obj.getbuffer
251
252 manager: FileManager
253 if isinstance(filename_or_obj, str): # path
254 manager = CachingFileManager(
255 _open_scipy_netcdf,
256 filename_or_obj,
257 mode=mode,
258 lock=lock,
259 kwargs=dict(mmap=mmap, version=version),
260 )
261 elif hasattr(filename_or_obj, "seek"): # file object
262 # Note: checking for .seek matches the check for file objects
263 # in scipy.io.netcdf_file
264 scipy_dataset = _open_scipy_netcdf(
265 filename_or_obj, # type: ignore[arg-type] # unsupported cases are caught above
266 mode=mode,
267 mmap=mmap,
268 version=version,
269 flush_only=True,
270 )
271 assert not scipy_dataset.use_mmap # no mmap for file objects
272 manager = DummyFileManager(scipy_dataset)
273 else:
274 raise ValueError(
275 f"cannot open {filename_or_obj=} with scipy.io.netcdf_file"
276 )
277
278 self._manager = manager
279

Callers

nothing calls this directly

Calls 5

get_write_lockFunction · 0.90
ensure_lockFunction · 0.90
CachingFileManagerClass · 0.90
DummyFileManagerClass · 0.90
_open_scipy_netcdfFunction · 0.85

Tested by

no test coverage detected