Skip to content

Commit 929cb62

Browse files
committed
Remove warning about resetting file pointer to zero
File pointer is reset to zero after reading the magic byte number anyway, so should be ok not to warn about this.
1 parent d2e84d2 commit 929cb62

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

xarray/core/utils.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -655,12 +655,6 @@ def read_magic_number_from_file(filename_or_obj, count=8) -> bytes:
655655
elif isinstance(filename_or_obj, io.IOBase):
656656
if filename_or_obj.tell() != 0:
657657
filename_or_obj.seek(0)
658-
warnings.warn(
659-
"cannot guess the engine, "
660-
"file-like object read/write pointer not at the start of the file, "
661-
"so resetting file pointer to zero. If this does not work, "
662-
"please close and reopen, or use a context manager"
663-
)
664658
magic_number = filename_or_obj.read(count)
665659
filename_or_obj.seek(0)
666660
else:

xarray/tests/test_backends.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3159,13 +3159,12 @@ def test_open_badbytes(self) -> None:
31593159
def test_open_twice(self) -> None:
31603160
expected = create_test_data()
31613161
expected.attrs["foo"] = "bar"
3162-
with pytest.warns(match=r"read/write pointer not at the start"):
3163-
with create_tmp_file() as tmp_file:
3164-
expected.to_netcdf(tmp_file, engine="h5netcdf")
3165-
with open(tmp_file, "rb") as f:
3162+
with create_tmp_file() as tmp_file:
3163+
expected.to_netcdf(tmp_file, engine="h5netcdf")
3164+
with open(tmp_file, "rb") as f:
3165+
with open_dataset(f, engine="h5netcdf"):
31663166
with open_dataset(f, engine="h5netcdf"):
3167-
with open_dataset(f, engine="h5netcdf"):
3168-
pass
3167+
pass
31693168

31703169
@requires_scipy
31713170
def test_open_fileobj(self) -> None:

0 commit comments

Comments
 (0)