[pycharm] PY-31070 Tables (Jupyter, DataView): Implement support of rec.arrays + fix headings displaying issue

GitOrigin-RevId: 11e2459a876bab393e4da04bcba47c9fd6345ba3
This commit is contained in:
ekaterina.itsenko
2025-01-29 10:37:58 +00:00
committed by intellij-monorepo-bot
parent 4752f9dea0
commit ba781919d1
9 changed files with 30 additions and 14 deletions
@@ -14,6 +14,7 @@ enum class NotebookOutputKeyType {
LETS_PLOT,
MARKDOWN,
NUMPY_ARRAY,
NUMPY_RECARRAY,
PANDAS_DATA_FRAME,
PANDAS_SERIES,
POLARS_DATA_FRAME,
@@ -89,7 +89,7 @@ def __get_table_provider(output):
import _pydevd_bundle.tables.pydevd_numpy_based as table_provider
else:
import _pydevd_bundle.tables.pydevd_numpy as table_provider
elif type_qualified_name == 'numpy.ndarray':
elif type_qualified_name == 'numpy.ndarray' or type_qualified_name == 'numpy.rec.recarray':
import _pydevd_bundle.tables.pydevd_numpy as table_provider
elif type_qualified_name in numpy_based_type_qualified_names:
import _pydevd_bundle.tables.pydevd_numpy_based as table_provider
@@ -630,6 +630,7 @@ def header_data_to_thrift_struct(rows, cols, dtypes, col_bounds, col_to_format,
TYPE_TO_THRIFT_STRUCT_CONVERTERS = {
"ndarray": array_to_thrift_struct,
"recarray": array_to_thrift_struct,
"EagerTensor": tensor_to_thrift_struct,
"ResourceVariable": tensor_to_thrift_struct,
"SparseTensor": sparse_tensor_to_thrift_struct,
@@ -836,6 +836,7 @@ def is_able_to_format_number(format):
TYPE_TO_XML_CONVERTERS = {
"ndarray": array_to_xml,
"recarray": array_to_xml,
"DataFrame": dataframe_to_xml,
"Series": dataframe_to_xml,
"GeoDataFrame": dataframe_to_xml,
@@ -31,6 +31,8 @@ def get_type(table):
def get_shape(table):
# type: (np.ndarray) -> str
if table.dtype.names is not None:
return str((table.shape[0], len(table.dtype.names)))
if table.ndim == 1:
return str((table.shape[0], 1))
else:
@@ -39,6 +41,9 @@ def get_shape(table):
def get_head(table):
# type: (np.ndarray) -> str
column_names = table.dtype.names
if column_names:
return TABLE_TYPE_NEXT_VALUE_SEPARATOR.join([str(column_names[i]) for i in range(len(column_names))])
return "None"
@@ -172,7 +177,8 @@ class _NpTable:
return ['<th>0</th>\n']
if self.type == WITH_TYPES:
return ['<th>{}</th>\n'.format(name) for name in self.array.dtype.names]
columns_names = self.array.dtype.names
return ['<th>{}</th>\n'.format(str(columns_names[i])) for i in range(len(columns_names))]
return ['<th>{}</th>\n'.format(i) for i in range(len(self.array[0]))]
@@ -33,18 +33,19 @@ public class PyDebugValue extends XNamedValue {
private static final String ARRAY = "Array";
private static final String DATA_FRAME = "DataFrame";
private static final String SERIES = "Series";
private static final Map<String, String> EVALUATOR_POSTFIXES = ImmutableMap.of(
"ndarray", ARRAY,
"EagerTensor", ARRAY,
"ResourceVariable", ARRAY,
"SparseTensor", ARRAY,
"Tensor", ARRAY,
DATA_FRAME, DATA_FRAME,
SERIES, SERIES,
"GeoDataFrame", DATA_FRAME,
"GeoSeries", SERIES,
"Dataset", DATA_FRAME
);
private static final Map<String, String> EVALUATOR_POSTFIXES = ImmutableMap.<String, String>builder()
.put("ndarray", ARRAY)
.put("recarray", ARRAY)
.put("EagerTensor", ARRAY)
.put("ResourceVariable", ARRAY)
.put("SparseTensor", ARRAY)
.put("Tensor", ARRAY)
.put(DATA_FRAME, DATA_FRAME)
.put(SERIES, SERIES)
.put("GeoDataFrame", DATA_FRAME)
.put("GeoSeries", SERIES)
.put("Dataset", DATA_FRAME)
.build();
private static final int MAX_ITEMS_TO_HANDLE = 100;
public static final int MAX_VALUE = 256;
public static final int AVAILABLE_PROCESSORS = Runtime.getRuntime().availableProcessors();
@@ -19,6 +19,10 @@ public class ArrayViewStrategy extends DataViewStrategy {
return new ArrayViewStrategy("ndarray");
}
public static @NotNull ArrayViewStrategy createInstanceForNumpyRecarray() {
return new ArrayViewStrategy("recarray");
}
public static @NotNull ArrayViewStrategy createInstanceForEagerTensor() {
return new ArrayViewStrategy("EagerTensor");
}
@@ -19,6 +19,7 @@ public abstract class DataViewStrategy {
private static class StrategyHolder {
private static final Set<DataViewStrategy> STRATEGIES = ImmutableSet.of(
ArrayViewStrategy.createInstanceForNumpyArray(),
ArrayViewStrategy.createInstanceForNumpyRecarray(),
ArrayViewStrategy.createInstanceForEagerTensor(),
ArrayViewStrategy.createInstanceForResourceVariable(),
ArrayViewStrategy.createInstanceForSparseTensor(),
@@ -65,6 +65,7 @@ public class PyViewNumericContainerAction extends XDebuggerTreeActionBase {
String nodeType = debugValue.getType();
if ("ndarray".equals(nodeType) ||
"recarray".equals(nodeType) ||
"EagerTensor".equals(nodeType) ||
"ResourceVariable".equals(nodeType) ||
"SparseTensor".equals(nodeType) ||