|
15 | 15 | from .client import InfluxDBClient
|
16 | 16 | from .line_protocol import _escape_tag
|
17 | 17 |
|
18 |
| -# Precisions factors must be int for correct calculation to ints. if float the result of a floor calc is an approximation |
19 |
| -# Example : the issue is only observable with nanosecond resolution values are greater than 895ns |
| 18 | +# Precisions factors must be int for correct calculation to ints. |
| 19 | +# if precision is a float the result of a floor calc is an approximation |
| 20 | +# Example : the issue is only observable with nanosecond resolution |
| 21 | +# values are greater than 895ns |
20 | 22 | # ts = pd.Timestamp('2013-01-01 23:10:55.123456987+00:00')
|
21 | 23 | # ts_ns = np.int64(ts.value)
|
22 | 24 | # # For conversion to microsecond
|
23 | 25 | # precision_factor=1e3
|
24 | 26 | # expected_ts_us = 1357081855123456
|
25 |
| -# np.int64(ts_ns // precision_factor) # results in INCORRECT 1357081855123457 |
26 |
| -# np.int64(ts_ns // np.int64(precision_factor) # results in CORRECT 1357081855123456 |
| 27 | +# # following is INCORRECT 1357081855123457 |
| 28 | +# np.int64(ts_ns // precision_factor) |
| 29 | +# # following is CORRECT 1357081855123456 |
| 30 | +# np.int64(ts_ns // np.int64(precision_factor) |
27 | 31 |
|
28 |
| -_time_precision_factors = { |
29 |
| - "n": 1, |
30 |
| - "u": np.int64(1e3), |
31 |
| - "ms": np.int64(1e6), |
32 |
| - "s": np.int64(1e9), |
33 |
| - "m": np.int64(1e9 * 60), |
34 |
| - "h": np.int64( 1e9 * 3600), |
35 |
| - } |
| 32 | +_time_precision_factors = {"n": 1, |
| 33 | + "u": np.int64(1e3), |
| 34 | + "ms": np.int64(1e6), |
| 35 | + "s": np.int64(1e9), |
| 36 | + "m": np.int64(1e9 * 60), |
| 37 | + "h": np.int64(1e9 * 3600), } |
36 | 38 |
|
37 | 39 |
|
38 | 40 | def _pandas_time_unit(time_precision):
|
@@ -280,7 +282,7 @@ def _convert_dataframe_to_json(dataframe,
|
280 | 282 | # Convert dtype for json serialization
|
281 | 283 | dataframe = dataframe.astype('object')
|
282 | 284 |
|
283 |
| - precision_factor =_time_precision_factors.get(time_precision, 1) |
| 285 | + precision_factor = _time_precision_factors.get(time_precision, 1) |
284 | 286 |
|
285 | 287 | points = [
|
286 | 288 | {'measurement': measurement,
|
@@ -343,11 +345,11 @@ def _convert_dataframe_to_lines(self,
|
343 | 345 | field_columns = list(column_series[~column_series.isin(
|
344 | 346 | tag_columns)])
|
345 | 347 |
|
346 |
| - precision_factor =_time_precision_factors.get(time_precision, 1) |
| 348 | + precision_factor = _time_precision_factors.get(time_precision, 1) |
347 | 349 |
|
348 | 350 | # Make array of timestamp ints
|
349 | 351 | if isinstance(dataframe.index, pd.PeriodIndex):
|
350 |
| - time = ((dataframe.index.to_timestamp().values.astype(np.int64) // |
| 352 | + time = ((dataframe.index.to_timestamp().values.astype(np.int64) // |
351 | 353 | precision_factor).astype(np.int64).astype(str))
|
352 | 354 | else:
|
353 | 355 | time = ((pd.to_datetime(dataframe.index).values.astype(np.int64) //
|
@@ -458,5 +460,5 @@ def _stringify_dataframe(dframe, numeric_precision, datatype='field'):
|
458 | 460 |
|
459 | 461 | def _datetime_to_epoch(self, datetime, time_precision='s'):
|
460 | 462 | nanoseconds = (datetime - self.EPOCH).value
|
461 |
| - precision_factor =_time_precision_factors.get(time_precision, 1) |
| 463 | + precision_factor = _time_precision_factors.get(time_precision, 1) |
462 | 464 | return np.int64(nanoseconds // np.int64(precision_factor))
|
0 commit comments