Skip to content

Commit a7cb9f2

Browse files
committed
Rename reset_encoding to drop_encoding
Closes pydata#8259
1 parent 1b0012a commit a7cb9f2

File tree

6 files changed

+21
-9
lines changed

6 files changed

+21
-9
lines changed

xarray/core/dataarray.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -914,9 +914,13 @@ def encoding(self, value: Mapping[Any, Any]) -> None:
914914
self.variable.encoding = dict(value)
915915

916916
def reset_encoding(self) -> Self:
917+
warnings.warn("reset_encoding is deprecated, use `drop_encoding` instead")
918+
self.drop_encoding()
919+
920+
def drop_encoding(self) -> Self:
917921
"""Return a new DataArray without encoding on the array or any attached
918922
coords."""
919-
ds = self._to_temp_dataset().reset_encoding()
923+
ds = self._to_temp_dataset().drop_encoding()
920924
return self._from_temp_dataset(ds)
921925

922926
@property

xarray/core/dataset.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -756,9 +756,13 @@ def encoding(self, value: Mapping[Any, Any]) -> None:
756756
self._encoding = dict(value)
757757

758758
def reset_encoding(self) -> Self:
759+
warnings.warn("reset_encoding is deprecated, use `drop_encoding` instead")
760+
self.drop_encoding()
761+
762+
def drop_encoding(self) -> Self:
759763
"""Return a new Dataset without encoding on the dataset or any of its
760764
variables/coords."""
761-
variables = {k: v.reset_encoding() for k, v in self.variables.items()}
765+
variables = {k: v.drop_encoding() for k, v in self.variables.items()}
762766
return self._replace(variables=variables, encoding={})
763767

764768
@property

xarray/core/variable.py

+4
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,10 @@ def encoding(self, value):
883883
raise ValueError("encoding must be castable to a dictionary")
884884

885885
def reset_encoding(self) -> Self:
886+
warnings.warn("reset_encoding is deprecated, use `drop_encoding` instead")
887+
self.drop_encoding()
888+
889+
def drop_encoding(self) -> Self:
886890
"""Return a new Variable without encoding."""
887891
return self._replace(encoding={})
888892

xarray/tests/test_dataarray.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ def test_encoding(self) -> None:
287287
self.dv.encoding = expected2
288288
assert expected2 is not self.dv.encoding
289289

290-
def test_reset_encoding(self) -> None:
290+
def test_drop_encoding(self) -> None:
291291
array = self.mda
292292
encoding = {"scale_factor": 10}
293293
array.encoding = encoding
@@ -296,7 +296,7 @@ def test_reset_encoding(self) -> None:
296296
assert array.encoding == encoding
297297
assert array["x"].encoding == encoding
298298

299-
actual = array.reset_encoding()
299+
actual = array.drop_encoding()
300300

301301
# did not modify in place
302302
assert array.encoding == encoding

xarray/tests/test_dataset.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2959,15 +2959,15 @@ def test_copy_with_data_errors(self) -> None:
29592959
with pytest.raises(ValueError, match=r"contain all variables in original"):
29602960
orig.copy(data={"var1": new_var1})
29612961

2962-
def test_reset_encoding(self) -> None:
2962+
def test_drop_encoding(self) -> None:
29632963
orig = create_test_data()
29642964
vencoding = {"scale_factor": 10}
29652965
orig.encoding = {"foo": "bar"}
29662966

29672967
for k, v in orig.variables.items():
29682968
orig[k].encoding = vencoding
29692969

2970-
actual = orig.reset_encoding()
2970+
actual = orig.drop_encoding()
29712971
assert actual.encoding == {}
29722972
for k, v in actual.variables.items():
29732973
assert v.encoding == {}

xarray/tests/test_variable.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -473,20 +473,20 @@ def test_encoding_preserved(self):
473473
assert_identical(expected.to_base_variable(), actual.to_base_variable())
474474
assert expected.encoding == actual.encoding
475475

476-
def test_reset_encoding(self) -> None:
476+
def test_drop_encoding(self) -> None:
477477
encoding1 = {"scale_factor": 1}
478478
# encoding set via cls constructor
479479
v1 = self.cls(["a"], [0, 1, 2], encoding=encoding1)
480480
assert v1.encoding == encoding1
481-
v2 = v1.reset_encoding()
481+
v2 = v1.drop_encoding()
482482
assert v1.encoding == encoding1
483483
assert v2.encoding == {}
484484

485485
# encoding set via setter
486486
encoding3 = {"scale_factor": 10}
487487
v3 = self.cls(["a"], [0, 1, 2], encoding=encoding3)
488488
assert v3.encoding == encoding3
489-
v4 = v3.reset_encoding()
489+
v4 = v3.drop_encoding()
490490
assert v3.encoding == encoding3
491491
assert v4.encoding == {}
492492

0 commit comments

Comments
 (0)