@@ -210,7 +210,7 @@ e.g. every 300 milliseconds:
210210
211211.. code-block :: python
212212
213- df = PeriodicDataFrame(interval = ' 300ms' , datafn = random_datapoint )
213+ df = PeriodicDataFrame(random_datapoint, interval = ' 300ms' )
214214
215215 ``df `` will now be a steady stream of whatever values are returned by
216216the `datafn `, which can of course be any Python code as long as it
@@ -220,33 +220,35 @@ Here we returned only a single point, appropriate for streaming the
220220results of system calls or other isolated actions, but any number of
221221entries can be returned by the dataframe in a single batch. To
222222facilitate collecting such batches, the callback is invoked with
223- ``last `` (the time of the previous invocation) and ``now `` (the
224- time of the current invocation). The callback can then generate or
225- query for just the values in that time range.
223+ keyword arguments ``last `` (the time of the previous invocation) and
224+ ``now `` (the time of the current invocation) as Pandas Timestamp
225+ objects. The callback can then generate or query for just the values
226+ in that time range.
226227
227228Arbitrary keyword arguments can be provided to the PeriodicDataFrame
228- constructor, which will be passed into the ` datafn ` when it is
229- called so that its behavior can be parameterized.
229+ constructor, which will be passed into the callback that its behavior
230+ can be parameterized.
230231
231232For instance, you can write a callback to return a suitable number of
232233datapoints to keep a regularly updating stream, generated randomly
233234as a batch since the last call:
234235
235236.. code-block :: python
236237
237- def random_datablock (last , now , ** kwargs ):
238- freq = pd.Timedelta(kwargs.get(" freq" , " 100ms" ))
239- index = pd.date_range(start = (last + freq.total_seconds()) * 1e9 ,
240- end = now * 1e9 , freq = freq)
241-
238+ def datablock (last , now , ** kwargs ):
239+ freq = kwargs.get(" freq" , pd.Timedelta(" 50ms" ))
240+ index = pd.date_range(start = last + freq, end = now, freq = freq)
242241 return pd.DataFrame({' x' : np.random.random(len (index))}, index = index)
243242
244- df = PeriodicDataFrame(random_datablock , interval = ' 300ms' , freq = ' 50ms ' )
243+ df = PeriodicDataFrame(datablock , interval = ' 300ms' )
245244
246- The callback will now be invoked every 300ms, each time generating datapoints
247- at a rate of 1 every 50ms, returned as a batch. Similar code could e.g. query
248- an external database for the time range since the last update, returning all
249- datapoints since then.
245+ The callback will now be invoked every 300ms, each time generating
246+ datapoints at a rate of 1 every 50ms, returned as a batch. If you
247+ wished, you could override the 50ms value by passing
248+ `freq=pd.Timedelta("100ms") ` to the PeriodicDataFrame constructor.
249+
250+ Similar code could e.g. query an external database for the time range
251+ since the last update, returning all datapoints since then.
250252
251253Once you have a PeriodicDataFrame defined using such callbacks, you
252254can then use all the rest of the functionality supported by streamz,
0 commit comments