Skip to content

Commit

Permalink
Add back data setter oops
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 638764523
  • Loading branch information
xingyousong authored and copybara-github committed May 30, 2024
1 parent e4e7688 commit 82c83c6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
13 changes: 13 additions & 0 deletions iris/normalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ def merge(self, data: Dict[str, Any]) -> None:
def data(self) -> Dict[str, Any]:
"""Returns copy of current data in buffer."""

@data.setter
@abc.abstractmethod
def data(self, new_data: Dict[str, Any]) -> None:
"""Sets data of buffer."""

@property
@abc.abstractmethod
def shape(self) -> Sequence[int]:
Expand Down Expand Up @@ -84,6 +89,10 @@ def merge(self, data: Dict[str, Any]) -> None:
def data(self) -> Dict[str, Any]:
return {}

@data.setter
def data(self, new_data: Dict[str, Any]) -> None:
pass

@property
def shape(self) -> Sequence[int]:
return ()
Expand Down Expand Up @@ -160,6 +169,10 @@ def merge(self, data: Dict[str, Any]) -> None:
def data(self) -> Dict[str, Any]:
return copy.deepcopy(self._data)

@data.setter
def data(self, new_data: Dict[str, Any]) -> None:
self._data = copy.deepcopy(new_data)

@property
def shape(self) -> Sequence[int]:
return self._shape
Expand Down
14 changes: 14 additions & 0 deletions iris/normalizer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@
from absl.testing import absltest


class BufferTest(absltest.TestCase):

def test_meanstdbuffer(self):
buffer = normalizer.MeanStdBuffer((1))
buffer.push(np.asarray(10.0))
buffer.push(np.asarray(11.0))

new_buffer = normalizer.MeanStdBuffer((1))
new_buffer.data = buffer.data

self.assertEqual(new_buffer._std, buffer._std)
self.assertEqual(new_buffer._data['n'], buffer._data['n'])


class NormalizerTest(absltest.TestCase):

def test_no_normalizer(self):
Expand Down

0 comments on commit 82c83c6

Please sign in to comment.