# Map function python error

**URL:** <https://community.influxdata.com/t/map-function-python-error/35036>\
**Category:** Fluxlang\
**Tags:** client-libraries, flux, python\
**Created:** [July 23, 2024, 3:33pm UTC](https://community.influxdata.com/t/map-function-python-error/35036 "2024-07-23T15:33:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fgarcia](https://avatars.discourse-cdn.com/v4/letter/f/a5b964/32.png) [@fgarcia](https://community.influxdata.com/u/fgarcia)\
**Post date:** [July 23, 2024, 3:33pm UTC](https://community.influxdata.com/t/map-function-python-error/35036/1 "2024-07-23T15:33:42Z")

</div>

Hello,

I’m trying to convert \_time column into int (or uint) while querying through python client library but I’m getting the error

```auto
Traceback (most recent call last):
  File "/home/ubuntu/python/push/push.py", line 62, in <module>
    run()
  File "/home/ubuntu/python/push/push.py", line 57, in run
    read_tables()
  File "/home/ubuntu/python/push/push.py", line 44, in read_tables
    tables = client.query_api().query('''import "strings"
KeyError: 'r with _time'

```

The piece of code is:

```auto
def read_tables():
    tables = client.query_api().query('''import "strings"
                                         from(bucket:"test")
                                         |> range(start: -{window_str}s)
                                         |> filter(fn: (r) => strings.hasPrefix(v: r._measurement, prefix: "WO"))
                                         |> map(fn: (r) => ({r with _time: int(v: r._time)}))
                                         |> drop(columns: ["_start", "_stop"])'''
                                         .format(window_str = window))

```

What I’m I doing wrong?

Thank you!

---

<div class="post-metadata">

**Author:** ![scott](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/scott/32/16492_2.png) [@scott](https://community.influxdata.com/u/scott)\
**Post date:** [July 23, 2024, 5:50pm UTC](https://community.influxdata.com/t/map-function-python-error/35036/2 "2024-07-23T17:50:07Z")

</div>

@fgarcia It looks like this error is coming from the client and not from Flux itself. I’m guessing that the Python client expects the `_time` column to be a time type. Try mapping the int/uint version of the timestamp to a different column.

```python
def read_tables():
    tables = client.query_api().query('''import "strings"
                                         from(bucket:"test")
                                         |> range(start: -{window_str}s)
                                         |> filter(fn: (r) => strings.hasPrefix(v: r._measurement, prefix: "WO"))
                                         |> map(fn: (r) => ({r with time_int: int(v: r._time)}))
                                         |> drop(columns: ["_start", "_stop"])'''
                                         .format(window_str = window))

```

---

<div class="post-metadata">

**Author:** ![fgarcia](https://avatars.discourse-cdn.com/v4/letter/f/a5b964/32.png) [@fgarcia](https://community.influxdata.com/u/fgarcia)\
**Post date:** [July 23, 2024, 6:08pm UTC](https://community.influxdata.com/t/map-function-python-error/35036/3 "2024-07-23T18:08:07Z")

</div>

Hi Scott,

Thank you for your help, unfortunately it did not work either.

I get the same error even if I try with “\_value” column

```auto
def read_tables():
    tables = client.query_api().query('''import "strings"
                                         from(bucket:"test")
                                         |> range(start: -{window_str}s)
                                         |> filter(fn: (r) => strings.hasPrefix(v: r._measurement, prefix: "WO"))
                                         |> map(fn: (r) => ({r with _value: int(v: r._value)}))
                                         |> drop(columns: ["_start", "_stop"])'''
                                         .format(window_str = window))

```

---

<div class="post-metadata">

**Author:** ![fgarcia](https://avatars.discourse-cdn.com/v4/letter/f/a5b964/32.png) [@fgarcia](https://community.influxdata.com/u/fgarcia)\
**Post date:** [July 23, 2024, 6:20pm UTC](https://community.influxdata.com/t/map-function-python-error/35036/4 "2024-07-23T18:20:38Z")

</div>

My bad!

Python code should be:

```auto
def read_tables():
    tables = client.query_api().query('''import "strings"
                                         from(bucket:"test")
                                         |> range(start: -{window_str}s)
                                         |> filter(fn: (r) => strings.hasPrefix(v: r._measurement, prefix: "WO"))
                                         |> map(fn: (r) => ({{r with _time: int(v: r._time)}}))
                                         |> drop(columns: ["_start", "_stop"])'''
                                         .format(window_str = window))

```

Double curly braces…

Thank you again!
