PY-34650 Python console crashes when trying to view a DataFrame with a Int64 column with nans

Use default formatter if formatting failed

Signed-off-by: Elizaveta Shashkova <Elizaveta.Shashkova@jetbrains.com>

GitOrigin-RevId: 90062c52ffe55c9fa74e41b3a4bbe6d4c6211ce1
This commit is contained in:
Elizaveta Shashkova
2020-06-09 20:48:34 +03:00
committed by intellij-monorepo-bot
parent f785d5980c
commit cb532cd236
2 changed files with 19 additions and 6 deletions
@@ -16,7 +16,7 @@ from _pydevd_bundle.pydevd_extension_api import TypeResolveProvider, StrPresenta
from _pydevd_bundle.pydevd_utils import take_first_n_coll_elements, is_numeric_container, is_pandas_container, is_string, pandas_to_str, \
should_evaluate_full_value, should_evaluate_shape
from _pydevd_bundle.pydevd_vars import get_label, array_default_format, is_able_to_format_number, MAXIMUM_ARRAY_SIZE, \
get_column_formatter_by_type, DEFAULT_DF_FORMAT
get_column_formatter_by_type, get_formatted_row_elements, DEFAULT_DF_FORMAT
from pydev_console.pydev_protocol import DebugValue, GetArrayResponse, ArrayData, ArrayHeaders, ColHeader, RowHeader, \
UnsupportedArrayTypeException, ExceedingArrayDimensionsException
@@ -549,10 +549,11 @@ def dataframe_to_thrift_struct(df, name, roffset, coffset, rows, cols, format):
iat = df.iat if dim == 1 or len(df.columns.unique()) == len(df.columns) else df.iloc
def formatted_row_elements(row):
return get_formatted_row_elements(row, iat, dim, cols, format, dtypes)
array_chunk.headers = header_data_to_thrift_struct(rows, cols, dtypes, col_bounds, col_to_format, df, dim)
array_chunk.data = array_data_to_thrift_struct(rows, cols,
lambda r: (("%" + col_to_format(c)) % (iat[r, c] if dim > 1 else iat[r])
for c in range(cols)), format)
array_chunk.data = array_data_to_thrift_struct(rows, cols, formatted_row_elements, format)
return array_chunk
@@ -595,6 +595,16 @@ def get_column_formatter_by_type(initial_format, column_type):
return array_default_format(column_type)
def get_formatted_row_elements(row, iat, dim, cols, format, dtypes):
for c in range(cols):
val = iat[row, c] if dim > 1 else iat[row]
col_formatter = get_column_formatter_by_type(format, dtypes[c])
try:
yield ("%" + col_formatter) % val
except TypeError:
yield ("%" + DEFAULT_DF_FORMAT) % val
def array_default_format(type):
if type == 'f':
return '.5f'
@@ -672,9 +682,11 @@ def dataframe_to_xml(df, name, roffset, coffset, rows, cols, format):
iat = df.iat if dim == 1 or len(df.columns.unique()) == len(df.columns) else df.iloc
def formatted_row_elements(row):
return get_formatted_row_elements(row, iat, dim, cols, format, dtypes)
xml += header_data_to_xml(rows, cols, dtypes, col_bounds, col_to_format, df, dim)
xml += array_data_to_xml(rows, cols, lambda r: (("%" + col_to_format(c)) % (iat[r, c] if dim > 1 else iat[r])
for c in range(cols)), format)
xml += array_data_to_xml(rows, cols, formatted_row_elements, format)
return xml