question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Data viewer doesn't like lists of datetime objects that all have a tzinfo

See original GitHub issue

Environment data

  • VS Code version: 1.36.0-insider 11b88a33
  • Extension version 2019.5.18875
  • OS and version: Current Arch Linux x86_64
  • Python version: 3.7.3
  • Type of virtual environment used: N/A
  • Relevant/affected Python packages and their versions: pandas 0.24.2
  • Jedi or Language Server? Jedi

Steps to reproduce:

Run the following script in the Python interactive window and inspect the variables list1 and list2 in the data viewer:

#%%
from datetime import datetime, timezone

#%% list1 displays just fine in the data viewer
list1 = [
    datetime(2019, 6, 22), 
    datetime(2019, 6, 22), 
    datetime(2019, 6, 22)]

#%% list2 shows all cells as "loading ..."
list2 = [
    datetime(2019, 6, 22, tzinfo=timezone.utc), 
    datetime(2019, 6, 22, tzinfo=timezone.utc), 
    datetime(2019, 6, 22, tzinfo=timezone.utc)]

#%%

Works for me just fine for list1:

image

but gets stuck at “loading …” for list2:

image

Note that I tried lists with various combinations of entries with and without tzinfo and the only szenario that seems to trigger the bug is when all are created with tzinfo.

Logs

Output from Console under the Developer Tools panel

This seem to be the relevant bit:

console.ts:134 [Extension Host] Error Python Extension: 2019-06-22 16:53:19: Failure during variable extraction:
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-e695ca9d874d> in <module>     31 # Turn into JSON using pandas. We use pandas because it's about 3 orders of magnitude faster to turn into JSON     32 _VSCODE_rows = _VSCODE_df.iloc[_VSCODE_startRow:_VSCODE_endRow]---> 33 _VSCODE_result = _VSCODE_pd_json.to_json(None, _VSCODE_rows, orient='table', date_format='iso')     34 print(_VSCODE_result)     35 
/usr/lib/python3.7/site-packages/pandas/io/json/json.py in to_json(path_or_buf, obj, orient, date_format, double_precision, force_ascii, date_unit, default_handler, lines, compression, index)     60         double_precision=double_precision, ensure_ascii=force_ascii,     61         date_unit=date_unit, default_handler=default_handler,---> 62         index=index).write()     63      64     if lines:
/usr/lib/python3.7/site-packages/pandas/io/json/json.py in __init__(self, obj, orient, date_format, double_precision, ensure_ascii, date_unit, index, default_handler)    184             raise ValueError(msg)    185 --> 186         self.schema = build_table_schema(obj, index=self.index)    187     188         # NotImplementd on a column MultiIndex
/usr/lib/python3.7/site-packages/pandas/io/json/table_schema.py in build_table_schema(data, index, primary_key, version)    242     if data.ndim > 1:    243         for column, s in data.iteritems():--> 244             fields.append(convert_pandas_type_to_json_field(s))    245     else:    246         fields.append(convert_pandas_type_to_json_field(data))
/usr/lib/python3.7/site-packages/pandas/io/json/table_schema.py in convert_pandas_type_to_json_field(arr, dtype)    112     elif is_datetime64tz_dtype(arr):    113         if hasattr(arr, 'dt'):--> 114             field['tz'] = arr.dt.tz.zone    115         else:    116             field['tz'] = arr.tz.zone
AttributeError: 'datetime.timezone' object has no attribute 'zone' (at t (/home/martin/.vscode-insiders/extensions/ms-python.python-2019.5.18875/out/client/extension.js:1:16618))
t.log @ console.ts:134
$logExtensionHostMessage @ mainThreadConsole.ts:38
_doInvokeHandler @ rpcProtocol.ts:394
_invokeHandler @ rpcProtocol.ts:379
_receiveRequest @ rpcProtocol.ts:299
_receiveOneMessage @ rpcProtocol.ts:226
_protocol.onMessage.e @ rpcProtocol.ts:101
fire @ event.ts:558
a @ ipc.net.ts:421
e @ ipc.net.ts:428
fire @ event.ts:558
_receiveMessage @ ipc.net.ts:715
S._socketDisposables.push._socketReader.onMessage.e @ ipc.net.ts:578
fire @ event.ts:558
acceptChunk @ ipc.net.ts:236
_register._socket.onData.e @ ipc.net.ts:197
t @ ipc.net.ts:28
emit @ events.js:182
addChunk @ _stream_readable.js:283
readableAddChunk @ _stream_readable.js:264
Readable.push @ _stream_readable.js:219
onStreamRead @ internal/stream_base_commons.js:94
console.ts:134 [Extension Host] Error Python Extension: 2019-06-22 16:53:19: [Error: Failure during variable extraction:
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-e695ca9d874d> in <module>     31 # Turn into JSON using pandas. We use pandas because it's about 3 orders of magnitude faster to turn into JSON     32 _VSCODE_rows = _VSCODE_df.iloc[_VSCODE_startRow:_VSCODE_endRow]---> 33 _VSCODE_result = _VSCODE_pd_json.to_json(None, _VSCODE_rows, orient='table', date_format='iso')     34 print(_VSCODE_result)     35 
/usr/lib/python3.7/site-packages/pandas/io/json/json.py in to_json(path_or_buf, obj, orient, date_format, double_precision, force_ascii, date_unit, default_handler, lines, compression, index)     60         double_precision=double_precision, ensure_ascii=force_ascii,     61         date_unit=date_unit, default_handler=default_handler,---> 62         index=index).write()     63      64     if lines:
/usr/lib/python3.7/site-packages/pandas/io/json/json.py in __init__(self, obj, orient, date_format, double_precision, ensure_ascii, date_unit, index, default_handler)    184             raise ValueError(msg)    185 --> 186         self.schema = build_table_schema(obj, index=self.index)    187     188         # NotImplementd on a column MultiIndex
/usr/lib/python3.7/site-packages/pandas/io/json/table_schema.py in build_table_schema(data, index, primary_key, version)    242     if data.ndim > 1:    243         for column, s in data.iteritems():--> 244             fields.append(convert_pandas_type_to_json_field(s))    245     else:    246         fields.append(convert_pandas_type_to_json_field(data))
/usr/lib/python3.7/site-packages/pandas/io/json/table_schema.py in convert_pandas_type_to_json_field(arr, dtype)    112     elif is_datetime64tz_dtype(arr):    113         if hasattr(arr, 'dt'):--> 114             field['tz'] = arr.dt.tz.zone    115         else:    116             field['tz'] = arr.tz.zone
AttributeError: 'datetime.timezone' object has no attribute 'zone'	at g.deserializeJupyterResult (/home/martin/.vscode-insiders/extensions/ms-python.python-2019.5.18875/out/client/extension.js:83:558667)	at g.runScript (/home/martin/.vscode-insiders/extensions/ms-python.python-2019.5.18875/out/client/extension.js:83:558235)] (at t (/home/martin/.vscode-insiders/extensions/ms-python.python-2019.5.18875/out/client/extension.js:1:16618))
t.log @ console.ts:134
$logExtensionHostMessage @ mainThreadConsole.ts:38
_doInvokeHandler @ rpcProtocol.ts:394
_invokeHandler @ rpcProtocol.ts:379
_receiveRequest @ rpcProtocol.ts:299
_receiveOneMessage @ rpcProtocol.ts:226
_protocol.onMessage.e @ rpcProtocol.ts:101
fire @ event.ts:558
a @ ipc.net.ts:421
e @ ipc.net.ts:428
fire @ event.ts:558
_receiveMessage @ ipc.net.ts:715
S._socketDisposables.push._socketReader.onMessage.e @ ipc.net.ts:578
fire @ event.ts:558
acceptChunk @ ipc.net.ts:236
_register._socket.onData.e @ ipc.net.ts:197
t @ ipc.net.ts:28
emit @ events.js:182
addChunk @ _stream_readable.js:283
readableAddChunk @ _stream_readable.js:264
Readable.push @ _stream_readable.js:219
onStreamRead @ internal/stream_base_commons.js:94

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ronglumscommented, Jun 29, 2019

@thierer Sorry for the confusion. I was referring to Rich’s comment above “We might be able to work around it using the hack described in the bug”, however we expect this hack will have a performance hit - therefore if we went that route, we’d also need to prompt a message saying that this could be slow.

0reactions
greazercommented, Feb 13, 2020

Thanks for the feedback! However, we don’t have plans on adding this functionality at this time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Data viewer doesn't like lists of datetime objects that all have a ...
Data viewer doesn't like lists of datetime objects that all have a tzinfo ... seems to trigger the bug is when all are...
Read more >
attribute 'tzinfo' of 'datetime.datetime' objects is not writable
I want to change it to EST. I'm trying, for example: class Book( db.Model ): creationTime = db.DateTimeProperty().
Read more >
Python - datetime.tzinfo() - GeeksforGeeks
The DateTime class provides various functions to manipulate the date and time intervals. The DateTime object which you use in datetime.now() ...
Read more >
datetime — Basic date and time types — Python 3.11.1 ...
These tzinfo objects capture information about the offset from UTC time, the time zone name, and whether daylight saving time is in effect....
Read more >
Working with datetime module and timezones in Python
This creates a datetime object, that does not have any information about the timezone, and uses the current time of the system. To...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found