Skip to content

Commit 77cac49

Browse files
authored
fix(data_frame): parsing empty query result value as numpy.NaN (influxdata#584)
1 parent 8fa5146 commit 77cac49

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
### Breaking Changes
44

5-
This release disables using of the HTTP proxy environment variables `HTTP_PROXY` and `HTTPS_PROXY` for the asynchronous HTTP client.
5+
This release disables using of the HTTP proxy environment variables `HTTP_PROXY` and `HTTPS_PROXY` for the asynchronous HTTP client.
66
The proxy environment variables must be explicitly enabled in the client's configuration:
77

88
```python
@@ -15,6 +15,7 @@ async with InfluxDBClientAsync(url="http://localhost:8086", token="my-token", or
1515

1616
### Bug Fixes
1717
1. [#583](https://github.com/influxdata/influxdb-client-python/pull/583): Async HTTP client doesn't always use `HTTP_PROXY`/`HTTPS_PROXY` environment variables. [async/await]
18+
1. [#584](https://github.com/influxdata/influxdb-client-python/pull/584): Parsing empty query result value as `numpy.NaN`
1819

1920
## 1.36.1 [2023-02-23]
2021

influxdb_client/client/flux_csv_parser.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ def _to_value(self, str_val, column):
272272
if str_val == '' or str_val is None:
273273
default_value = column.default_value
274274
if default_value == '' or default_value is None:
275+
if self._serialization_mode is FluxSerializationMode.dataFrame:
276+
from ..extras import np
277+
return self._to_value(np.nan, column)
275278
return None
276279
return self._to_value(default_value, column)
277280

tests/test_FluxCSVParser.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,19 @@ def test_pandas_column_datatype(self):
263263
self.assertEqual('bool', df.dtypes['value4'].name)
264264
self.assertEqual('float64', df.dtypes['value5'].name)
265265

266+
def test_pandas_null_bool_types(self):
267+
data = "#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,string,string,string,string,boolean\n" \
268+
"#group,false,false,true,true,true,true,true,true,false\n" \
269+
"#default,_result,,,,,,,,\n" \
270+
",result,table,_start,_stop,_field,_measurement,host,region,value\n" \
271+
",,0,1977-09-21T00:12:43.145224192Z,2018-07-16T11:21:02.547596934Z,free,mem,A,west,true\n" \
272+
",,0,1977-09-21T00:12:43.145224192Z,2018-07-16T11:21:02.547596934Z,free,mem,A,west,\n"
273+
274+
parser = self._parse(data=data, serialization_mode=FluxSerializationMode.dataFrame,
275+
response_metadata_mode=FluxResponseMetadataMode.full)
276+
df = list(parser.generator())[0]
277+
self.assertEqual('bool', df.dtypes['value'].name)
278+
266279
def test_parse_without_datatype(self):
267280
data = ",result,table,_start,_stop,_field,_measurement,host,region,_value2,value1,value_str\n" \
268281
",,0,1677-09-21T00:12:43.145224192Z,2018-07-16T11:21:02.547596934Z,free,mem,A,west,121,11,test\n" \

0 commit comments

Comments
 (0)