77
88import nitypes .bintime as bt
99import numpy as np
10- from ni .protobuf .types import attribute_value_pb2 , scalar_pb2 , array_pb2
11- from ni .protobuf .types .precision_timestamp_pb2 import PrecisionTimestamp
12- from ni .protobuf .types .scalar_conversion import scalar_from_protobuf , scalar_to_protobuf
10+ from ni .protobuf .types import scalar_pb2 , array_pb2
1311from ni .protobuf .types .precision_timestamp_conversion import (
1412 bintime_datetime_from_protobuf ,
1513 bintime_datetime_to_protobuf ,
1614)
15+ from ni .protobuf .types .precision_timestamp_pb2 import PrecisionTimestamp
16+ from ni .protobuf .types .scalar_conversion import scalar_from_protobuf , scalar_to_protobuf
1717from ni .protobuf .types .waveform_conversion import (
1818 float64_analog_waveform_from_protobuf ,
1919 float64_analog_waveform_to_protobuf ,
@@ -63,15 +63,11 @@ def protobuf_message(self) -> Type[array_pb2.BytesArray]:
6363 """The type-specific protobuf message for the Python type."""
6464 return array_pb2 .BytesArray
6565
66- def to_protobuf_message (
67- self , python_value : Collection [bytes ]
68- ) -> array_pb2 .BytesArray :
66+ def to_protobuf_message (self , python_value : Collection [bytes ]) -> array_pb2 .BytesArray :
6967 """Convert the collection of byte strings to array_pb2.BytesArray."""
7068 return self .protobuf_message (values = python_value )
7169
72- def to_python_value (
73- self , protobuf_message : array_pb2 .BytesArray
74- ) -> Collection [bytes ]:
70+ def to_python_value (self , protobuf_message : array_pb2 .BytesArray ) -> Collection [bytes ]:
7571 """Convert the protobuf message to a Python collection of byte strings."""
7672 return list (protobuf_message .values )
7773
@@ -89,15 +85,11 @@ def protobuf_message(self) -> Type[array_pb2.DoubleArray]:
8985 """The type-specific protobuf message for the Python type."""
9086 return array_pb2 .DoubleArray
9187
92- def to_protobuf_message (
93- self , python_value : Collection [float ]
94- ) -> array_pb2 .DoubleArray :
88+ def to_protobuf_message (self , python_value : Collection [float ]) -> array_pb2 .DoubleArray :
9589 """Convert the collection of floats to array_pb2.DoubleArray."""
9690 return self .protobuf_message (values = python_value )
9791
98- def to_python_value (
99- self , protobuf_message : array_pb2 .DoubleArray
100- ) -> Collection [float ]:
92+ def to_python_value (self , protobuf_message : array_pb2 .DoubleArray ) -> Collection [float ]:
10193 """Convert the protobuf message to a Python collection of floats."""
10294 return list (protobuf_message .values )
10395
@@ -137,20 +129,15 @@ def protobuf_message(self) -> Type[array_pb2.StringArray]:
137129 """The type-specific protobuf message for the Python type."""
138130 return array_pb2 .StringArray
139131
140- def to_protobuf_message (
141- self , python_value : Collection [str ]
142- ) -> array_pb2 .StringArray :
132+ def to_protobuf_message (self , python_value : Collection [str ]) -> array_pb2 .StringArray :
143133 """Convert the collection of strings to panel_types_pb2.StringCollection."""
144134 return self .protobuf_message (values = python_value )
145135
146- def to_python_value (
147- self , protobuf_message : array_pb2 .StringArray
148- ) -> Collection [str ]:
136+ def to_python_value (self , protobuf_message : array_pb2 .StringArray ) -> Collection [str ]:
149137 """Convert the protobuf message to a Python collection of strings."""
150138 return list (protobuf_message .values )
151139
152140
153-
154141class Double2DArrayConverter (CollectionConverter2D [float , array_pb2 .Double2DArray ]):
155142 """A converter between Collection[Collection[float]] and Double2DArray."""
156143
@@ -164,8 +151,10 @@ def protobuf_message(self) -> Type[array_pb2.Double2DArray]:
164151 """The type-specific protobuf message for the Python type."""
165152 return array_pb2 .Double2DArray
166153
167- def to_protobuf_message (self , python_value : Collection [Collection [float ]]) -> array_pb2 .Double2DArray :
168- """Convert the Python Collection[Collection[float]] to a protobuf array_pb2.Double2DArray."""
154+ def to_protobuf_message (
155+ self , python_value : Collection [Collection [float ]]
156+ ) -> array_pb2 .Double2DArray :
157+ """Convert the Python Collection[Collection[float]] to a protobuf Double2DArray."""
169158 rows = len (python_value )
170159 if rows :
171160 visitor = iter (python_value )
@@ -180,8 +169,10 @@ def to_protobuf_message(self, python_value: Collection[Collection[float]]) -> ar
180169 flat_list = [item for subcollection in python_value for item in subcollection ]
181170 return array_pb2 .Double2DArray (rows = rows , columns = columns , data = flat_list )
182171
183- def to_python_value (self , protobuf_message : array_pb2 .Double2DArray ) -> Collection [Collection [float ]]:
184- """Convert the protobuf array_pb2.Double2DArray to a Python Collection[Collection[float]]."""
172+ def to_python_value (
173+ self , protobuf_message : array_pb2 .Double2DArray
174+ ) -> Collection [Collection [float ]]:
175+ """Convert the protobuf Double2DArray to a Python Collection[Collection[float]]."""
185176 if not protobuf_message .data :
186177 return []
187178 if len (protobuf_message .data ) % protobuf_message .columns != 0 :
0 commit comments