Skip to content

Commit 173f46b

Browse files
authored
Fix raw-read Function Names Spacing Issue (#492)
* fix name spacing issue * minor edit * Address comment * Add test for deprecated functions * fix lint error * address comments * Minor edit
1 parent 3d67f7d commit 173f46b

File tree

3 files changed

+89
-6
lines changed

3 files changed

+89
-6
lines changed

generated/nidaqmx/_task_modules/in_stream.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,8 +1086,12 @@ def read(self, number_of_samples_per_channel=READ_ALL_AVAILABLE):
10861086
if number_of_channels * samples_read != number_of_samples:
10871087
return numpy_array[:number_of_channels * samples_read]
10881088
return numpy_array
1089-
1089+
1090+
@deprecation.deprecated(deprecated_in="1.0.0", removed_in="1.2.0", details="Use read_all instead.")
10901091
def readall(self):
1092+
return self.read_all()
1093+
1094+
def read_all(self):
10911095
"""
10921096
Reads all available raw samples from the task or virtual channels
10931097
you specify.
@@ -1137,7 +1141,11 @@ def readall(self):
11371141
"""
11381142
return self.read(number_of_samples_per_channel=READ_ALL_AVAILABLE)
11391143

1144+
@deprecation.deprecated(deprecated_in="1.0.0", removed_in="1.2.0", details="Use read_into instead.")
11401145
def readinto(self, numpy_array):
1146+
return self.read_into(numpy_array)
1147+
1148+
def read_into(self, numpy_array):
11411149
"""
11421150
Reads raw samples from the task or virtual channels you specify
11431151
into numpy_array.

src/codegen/templates/_task_modules/in_stream.py.mako

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,12 @@ ${property_template.script_property(attribute)}\
207207
if number_of_channels * samples_read != number_of_samples:
208208
return numpy_array[:number_of_channels * samples_read]
209209
return numpy_array
210-
210+
211+
@deprecation.deprecated(deprecated_in="1.0.0", removed_in="1.2.0", details="Use read_all instead.")
211212
def readall(self):
213+
return self.read_all()
214+
215+
def read_all(self):
212216
"""
213217
Reads all available raw samples from the task or virtual channels
214218
you specify.
@@ -258,7 +262,11 @@ ${property_template.script_property(attribute)}\
258262
"""
259263
return self.read(number_of_samples_per_channel=READ_ALL_AVAILABLE)
260264

265+
@deprecation.deprecated(deprecated_in="1.0.0", removed_in="1.2.0", details="Use read_into instead.")
261266
def readinto(self, numpy_array):
267+
return self.read_into(numpy_array)
268+
269+
def read_into(self, numpy_array):
262270
"""
263271
Reads raw samples from the task or virtual channels you specify
264272
into numpy_array.

tests/component/_task_modules/test_in_stream.py

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ def test___ai_finite_task___readall___returns_valid_samples_shape_and_dtype(
6464
rate=1000.0, sample_mode=AcquisitionType.FINITE, samps_per_chan=100
6565
)
6666

67-
data = ai_sine_task.in_stream.readall()
67+
with pytest.deprecated_call():
68+
data = ai_sine_task.in_stream.readall()
6869

6970
assert data.shape == (ai_sine_task.number_of_channels * 100,)
7071
assert data.dtype == numpy.int16
@@ -83,7 +84,8 @@ def test___ai_continuous_task___readall___returns_valid_samples_shape_and_dtype(
8384
while ai_sine_task.in_stream.avail_samp_per_chan < min_samples_per_channel:
8485
time.sleep(10e-3)
8586

86-
data = ai_sine_task.in_stream.readall()
87+
with pytest.deprecated_call():
88+
data = ai_sine_task.in_stream.readall()
8789

8890
assert data.shape[0] >= ai_sine_task.number_of_channels * min_samples_per_channel
8991
assert data.shape[0] % ai_sine_task.number_of_channels == 0
@@ -100,7 +102,8 @@ def test___valid_array___readinto___returns_valid_samples(
100102
ai_sine_task.number_of_channels * samples_to_read, FULLSCALE_RAW_MAX, dtype=numpy.int16
101103
)
102104

103-
samples_read = ai_sine_task.in_stream.readinto(data)
105+
with pytest.deprecated_call():
106+
samples_read = ai_sine_task.in_stream.readinto(data)
104107

105108
assert samples_read == samples_to_read
106109
assert (SINE_RAW_MIN <= data).all() and (data <= SINE_RAW_MAX).all()
@@ -113,7 +116,71 @@ def test___odd_sized_array___readinto___returns_whole_samples_and_clears_padding
113116
# Initialize the array to full-scale readings to ensure it is overwritten.
114117
data = numpy.full(19, FULLSCALE_RAW_MIN, dtype=numpy.int16)
115118

116-
samples_read = task.in_stream.readinto(data)
119+
with pytest.deprecated_call():
120+
samples_read = task.in_stream.readinto(data)
121+
122+
assert samples_read == 9
123+
assert (SINE_RAW_MIN <= data[:-1]).all() and (data[:-1] <= SINE_RAW_MAX).all()
124+
assert data[-1] == 0 # not FULLSCALE_RAW_MIN
125+
126+
127+
def test___ai_finite_task___read_all___returns_valid_samples_shape_and_dtype(
128+
ai_sine_task: nidaqmx.Task,
129+
) -> None:
130+
ai_sine_task.timing.cfg_samp_clk_timing(
131+
rate=1000.0, sample_mode=AcquisitionType.FINITE, samps_per_chan=100
132+
)
133+
134+
data = ai_sine_task.in_stream.read_all()
135+
136+
assert data.shape == (ai_sine_task.number_of_channels * 100,)
137+
assert data.dtype == numpy.int16
138+
assert (SINE_RAW_MIN <= data).all() and (data <= SINE_RAW_MAX).all()
139+
140+
141+
def test___ai_continuous_task___read_all___returns_valid_samples_shape_and_dtype(
142+
ai_sine_task: nidaqmx.Task,
143+
) -> None:
144+
ai_sine_task.timing.cfg_samp_clk_timing(
145+
rate=1000.0, sample_mode=AcquisitionType.CONTINUOUS, samps_per_chan=1000
146+
)
147+
ai_sine_task.start()
148+
# Wait until there are some samples to read.
149+
min_samples_per_channel = 100
150+
while ai_sine_task.in_stream.avail_samp_per_chan < min_samples_per_channel:
151+
time.sleep(10e-3)
152+
153+
data = ai_sine_task.in_stream.read_all()
154+
155+
assert data.shape[0] >= ai_sine_task.number_of_channels * min_samples_per_channel
156+
assert data.shape[0] % ai_sine_task.number_of_channels == 0
157+
assert data.dtype == numpy.int16
158+
assert (SINE_RAW_MIN <= data).all() and (data <= SINE_RAW_MAX).all()
159+
160+
161+
@pytest.mark.parametrize("samples_to_read", [1, 10])
162+
def test___valid_array___read_into___returns_valid_samples(
163+
ai_sine_task: nidaqmx.Task, samples_to_read: int
164+
) -> None:
165+
# Initialize the array to full-scale readings to ensure it is overwritten.
166+
data = numpy.full(
167+
ai_sine_task.number_of_channels * samples_to_read, FULLSCALE_RAW_MAX, dtype=numpy.int16
168+
)
169+
170+
samples_read = ai_sine_task.in_stream.read_into(data)
171+
172+
assert samples_read == samples_to_read
173+
assert (SINE_RAW_MIN <= data).all() and (data <= SINE_RAW_MAX).all()
174+
175+
176+
def test___odd_sized_array___read_into___returns_whole_samples_and_clears_padding(
177+
task: nidaqmx.Task, sim_x_series_device: nidaqmx.system.Device
178+
) -> None:
179+
_create_ai_sine_channels(task, sim_x_series_device, number_of_channels=2)
180+
# Initialize the array to full-scale readings to ensure it is overwritten.
181+
data = numpy.full(19, FULLSCALE_RAW_MIN, dtype=numpy.int16)
182+
183+
samples_read = task.in_stream.read_into(data)
117184

118185
assert samples_read == 9
119186
assert (SINE_RAW_MIN <= data[:-1]).all() and (data[:-1] <= SINE_RAW_MAX).all()

0 commit comments

Comments
 (0)