mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
[PyCharm Tables] PY-77129 fixed tables python tests
* fixed 3 configurations when we don't install pandas * fixed tests where the changing tests was missed after implementation changes * changed python 3.7 to python 3.12 Merge-request: IJ-MR-149361 Merged-by: Natalia Murycheva <natalia.murycheva@jetbrains.com> (cherry picked from commit f154e99b8986a3f476bd7424d34e0b894991fb33) GitOrigin-RevId: 9f5b92d8cb3937b59c491018bc1cb3d9b5ecf539
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a9ce4d15f3
commit
2a97339f9c
@@ -36,7 +36,7 @@ def get_column_types(table):
|
||||
# used by pydevd
|
||||
# noinspection PyUnresolvedReferences
|
||||
def get_data(table, use_csv_serialization, start_index=None, end_index=None, format=None):
|
||||
# type: (Union[pd.DataFrame, pd.Series], int, int) -> str
|
||||
# type: (Union[pd.DataFrame, pd.Series], bool, int, int) -> str
|
||||
|
||||
def convert_data_to_csv(data):
|
||||
return repr(__convert_to_df(data).to_csv(na_rep = "NaN", float_format=format, sep=CSV_FORMAT_SEPARATOR))
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<type 'numpy.ndarray'>
|
||||
__pydev_val__
|
||||
(3, 3)
|
||||
__pydev_val__
|
||||
None
|
||||
__pydev_val__
|
||||
int64__pydev_table_column_type_val__int64__pydev_table_column_type_val__int64__pydev_table_column_type_val__int64
|
||||
@@ -0,0 +1,7 @@
|
||||
<class 'numpy.ndarray'>
|
||||
__pydev_val__
|
||||
(3, 3)
|
||||
__pydev_val__
|
||||
None
|
||||
__pydev_val__
|
||||
int64__pydev_table_column_type_val__int64__pydev_table_column_type_val__int64__pydev_table_column_type_val__int64
|
||||
@@ -0,0 +1,7 @@
|
||||
<class 'numpy.ndarray'>
|
||||
__pydev_val__
|
||||
(3, 3)
|
||||
__pydev_val__
|
||||
None
|
||||
__pydev_val__
|
||||
int64__pydev_table_column_type_val__int64__pydev_table_column_type_val__int64__pydev_table_column_type_val__int64
|
||||
@@ -1,7 +0,0 @@
|
||||
<class 'numpy.ndarray'>
|
||||
__pydev_val__
|
||||
3
|
||||
__pydev_val__
|
||||
'<table class="dataframe">\n<thead>\n<tr style="text-align: right;">\n<th></th>\n<th>0</th>\n<th>1</th>\n<th>2</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<th>0</th>\n<td>1</td>\n<td>2</td>\n<td>3</td>\n</tr>\n<tr>\n<th>1</th>\n<td>4</td>\n<td>5</td>\n<td>6</td>\n</tr>\n<tr>\n<th>2</th>\n<td>7</td>\n<td>8</td>\n<td>9</td>\n</tr>\n</tbody>\n</table>\n'
|
||||
__pydev_val__
|
||||
int64__pydev_table_column_type_val__int64__pydev_table_column_type_val__int64__pydev_table_column_type_val__int64
|
||||
@@ -0,0 +1,7 @@
|
||||
<type 'numpy.ndarray'>
|
||||
__pydev_val__
|
||||
(2, 1)
|
||||
__pydev_val__
|
||||
None
|
||||
__pydev_val__
|
||||
int64__pydev_table_column_type_val__int32__pydev_table_column_type_val__float32__pydev_table_column_type_val__<U16__pydev_table_column_type_val__bool
|
||||
@@ -0,0 +1,7 @@
|
||||
<class 'numpy.ndarray'>
|
||||
__pydev_val__
|
||||
(2, 1)
|
||||
__pydev_val__
|
||||
None
|
||||
__pydev_val__
|
||||
int64__pydev_table_column_type_val__int32__pydev_table_column_type_val__float32__pydev_table_column_type_val__<U16__pydev_table_column_type_val__bool
|
||||
@@ -0,0 +1,7 @@
|
||||
<class 'numpy.ndarray'>
|
||||
__pydev_val__
|
||||
(2, 1)
|
||||
__pydev_val__
|
||||
None
|
||||
__pydev_val__
|
||||
int64__pydev_table_column_type_val__int32__pydev_table_column_type_val__float32__pydev_table_column_type_val__<U16__pydev_table_column_type_val__bool
|
||||
@@ -1,7 +0,0 @@
|
||||
<class 'numpy.ndarray'>
|
||||
__pydev_val__
|
||||
2
|
||||
__pydev_val__
|
||||
'<table class="dataframe">\n<thead>\n<tr style="text-align: right;">\n<th></th>\n<th>ci</th>\n<th>cf</th>\n<th>cs</th>\n<th>cb</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<th>0</th>\n<td>10</td>\n<td>3.140000104904175</td>\n<td>Hello</td>\n<td>True</td>\n</tr>\n<tr>\n<th>1</th>\n<td>20</td>\n<td>2.7100000381469727</td>\n<td>World</td>\n<td>False</td>\n</tr>\n</tbody>\n</table>\n'
|
||||
__pydev_val__
|
||||
int64__pydev_table_column_type_val__int32__pydev_table_column_type_val__float32__pydev_table_column_type_val__<U16__pydev_table_column_type_val__bool
|
||||
@@ -0,0 +1,7 @@
|
||||
<type 'numpy.ndarray'>
|
||||
__pydev_val__
|
||||
(2, 3)
|
||||
__pydev_val__
|
||||
None
|
||||
__pydev_val__
|
||||
int64__pydev_table_column_type_val__|S5__pydev_table_column_type_val__|S5__pydev_table_column_type_val__|S5
|
||||
@@ -0,0 +1,7 @@
|
||||
<class 'numpy.ndarray'>
|
||||
__pydev_val__
|
||||
(2, 3)
|
||||
__pydev_val__
|
||||
None
|
||||
__pydev_val__
|
||||
int64__pydev_table_column_type_val__<U5__pydev_table_column_type_val__<U5__pydev_table_column_type_val__<U5
|
||||
@@ -0,0 +1,7 @@
|
||||
<class 'numpy.ndarray'>
|
||||
__pydev_val__
|
||||
(2, 3)
|
||||
__pydev_val__
|
||||
None
|
||||
__pydev_val__
|
||||
int64__pydev_table_column_type_val__<U5__pydev_table_column_type_val__<U5__pydev_table_column_type_val__<U5
|
||||
@@ -1,7 +0,0 @@
|
||||
<class 'numpy.ndarray'>
|
||||
__pydev_val__
|
||||
2
|
||||
__pydev_val__
|
||||
'<table class="dataframe">\n<thead>\n<tr style="text-align: right;">\n<th></th>\n<th>0</th>\n<th>1</th>\n<th>2</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<th>0</th>\n<td>True</td>\n<td>False</td>\n<td>True</td>\n</tr>\n<tr>\n<th>1</th>\n<td>True</td>\n<td>True</td>\n<td>False</td>\n</tr>\n</tbody>\n</table>\n'
|
||||
__pydev_val__
|
||||
int64__pydev_table_column_type_val__<U5__pydev_table_column_type_val__<U5__pydev_table_column_type_val__<U5
|
||||
@@ -0,0 +1,7 @@
|
||||
<type 'numpy.ndarray'>
|
||||
__pydev_val__
|
||||
(3, 1)
|
||||
__pydev_val__
|
||||
None
|
||||
__pydev_val__
|
||||
int64__pydev_table_column_type_val__int64
|
||||
@@ -0,0 +1,7 @@
|
||||
<class 'numpy.ndarray'>
|
||||
__pydev_val__
|
||||
(3, 1)
|
||||
__pydev_val__
|
||||
None
|
||||
__pydev_val__
|
||||
int64__pydev_table_column_type_val__int64
|
||||
@@ -0,0 +1,7 @@
|
||||
<class 'numpy.ndarray'>
|
||||
__pydev_val__
|
||||
(3, 1)
|
||||
__pydev_val__
|
||||
None
|
||||
__pydev_val__
|
||||
int64__pydev_table_column_type_val__int64
|
||||
@@ -1,7 +0,0 @@
|
||||
<class 'numpy.ndarray'>
|
||||
__pydev_val__
|
||||
3
|
||||
__pydev_val__
|
||||
'<table class="dataframe">\n<thead>\n<tr style="text-align: right;">\n<th></th>\n<th>0</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<th>0</th>\n<td>1</td>\n</tr>\n<tr>\n<th>1</th>\n<td>2</td>\n</tr>\n<tr>\n<th>2</th>\n<td>3</td>\n</tr>\n</tbody>\n</table>\n'
|
||||
__pydev_val__
|
||||
int64__pydev_table_column_type_val__int64
|
||||
@@ -2,6 +2,6 @@
|
||||
__pydev_val__
|
||||
4
|
||||
__pydev_val__
|
||||
'<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border="1" class="dataframe">\n <thead>\n <tr style="text-align: right;">\n <th></th>\n <th>A</th>\n <th>B</th>\n <th>C</th>\n <th>D</th>\n <th>E</th>\n <th>F</th>\n <th>G</th>\n <th>H</th>\n <th>I</th>\n <th>J</th>\n <th>K</th>\n <th>L</th>\n <th>datetime64[ns]</th>\n <th>datetime64[ns, <tz>]</th>\n <th>period</th>\n <th>category</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>1.0</td>\n <td>foo</td>\n <td>None</td>\n <td>1.0+20.0j</td>\n <td>1.0+20.0j</td>\n <td>None</td>\n <td>None</td>\n <td>True</td>\n <td>2013-01-02</td>\n <td>1.0</td>\n <td>0</td>\n <td>test</td>\n <td>2001-01-02</td>\n <td>2013-01-01 00:00:00+01:00</td>\n <td>2012-01-01</td>\n <td>A</td>\n </tr>\n <tr>\n <th>1</th>\n <td>1.0</td>\n <td>foo</td>\n <td>None</td>\n <td>1.0+20.0j</td>\n <td>1.0+20.0j</td>\n <td>bar</td>\n <td>bar</td>\n <td>False</td>\n <td>2013-01-02</td>\n <td>1.0</td>\n <td>1</td>\n <td>train</td>\n <td>2001-01-02</td>\n <td>2013-01-02 00:00:00+01:00</td>\n <td>2012-01-01</td>\n <td>B</td>\n </tr>\n <tr>\n <th>2</th>\n <td>1.0</td>\n <td>foo</td>\n <td>None</td>\n <td>1.0+20.0j</td>\n <td>1.0+20.0j</td>\n <td>2.0</td>\n <td>2.0</td>\n <td>True</td>\n <td>2013-01-02</td>\n <td>1.0</td>\n <td>2</td>\n <td>test</td>\n <td>2001-01-02</td>\n <td>2013-01-03 00:00:00+01:00</td>\n <td>2012-01-01</td>\n <td>C</td>\n </tr>\n <tr>\n <th>3</th>\n <td>1.0</td>\n <td>foo</td>\n <td>None</td>\n <td>1.0+20.0j</td>\n <td>1.0+20.0j</td>\n <td>(1+10j)</td>\n <td>(1+10j)</td>\n <td>False</td>\n <td>2013-01-02</td>\n <td>1.0</td>\n <td>3</td>\n <td>train</td>\n <td>2001-01-02</td>\n <td>2013-01-04 00:00:00+01:00</td>\n <td>2012-01-01</td>\n <td>D</td>\n </tr>\n </tbody>\n</table>\n</div>'
|
||||
'<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border="1" class="dataframe">\n <thead>\n <tr style="text-align: right;">\n <th></th>\n <th>A</th>\n <th>B</th>\n <th>C</th>\n <th>D</th>\n <th>E</th>\n <th>F</th>\n <th>G</th>\n <th>H</th>\n <th>I</th>\n <th>J</th>\n <th>K</th>\n <th>L</th>\n <th>datetime64[ns]</th>\n <th>datetime64[ns, <tz>]</th>\n <th>period</th>\n <th>category</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>1.0</td>\n <td>foo</td>\n <td>None</td>\n <td>1.0+20.0j</td>\n <td>1.0+20.0j</td>\n <td>None</td>\n <td>None</td>\n <td>True</td>\n <td>2013-01-02</td>\n <td>1.0</td>\n <td>0</td>\n <td>test</td>\n <td>2001-01-02</td>\n <td>2013-01-01 00:00:00+01:00</td>\n <td>2012-01-01</td>\n <td>A</td>\n </tr>\n </tbody>\n</table>\n</div>'
|
||||
__pydev_val__
|
||||
int64__pydev_table_column_type_val__float64__pydev_table_column_type_val__object__pydev_table_column_type_val__object__pydev_table_column_type_val__complex128__pydev_table_column_type_val__complex128__pydev_table_column_type_val__object__pydev_table_column_type_val__object__pydev_table_column_type_val__bool__pydev_table_column_type_val__datetime64[ns]__pydev_table_column_type_val__float32__pydev_table_column_type_val__int32__pydev_table_column_type_val__category__pydev_table_column_type_val__datetime64[ns]__pydev_table_column_type_val__datetime64[ns, CET]__pydev_table_column_type_val__period[D]__pydev_table_column_type_val__category
|
||||
@@ -1,40 +1,48 @@
|
||||
# Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
import pytest
|
||||
import numpy as np
|
||||
import _pydevd_bundle.tables.pydevd_numpy as pandas_tables_helpers
|
||||
import pytest
|
||||
import sys
|
||||
import _pydevd_bundle.tables.pydevd_numpy as numpy_tables_helpers
|
||||
from _pydevd_bundle.pydevd_constants import NEXT_VALUE_SEPARATOR
|
||||
|
||||
|
||||
def check_info_np_array(arr, file):
|
||||
actual = [pandas_tables_helpers.get_type(arr),
|
||||
actual = [numpy_tables_helpers.get_type(arr),
|
||||
NEXT_VALUE_SEPARATOR,
|
||||
pandas_tables_helpers.get_shape(arr),
|
||||
numpy_tables_helpers.get_shape(arr),
|
||||
NEXT_VALUE_SEPARATOR,
|
||||
pandas_tables_helpers.get_head(arr),
|
||||
numpy_tables_helpers.get_head(arr),
|
||||
NEXT_VALUE_SEPARATOR,
|
||||
pandas_tables_helpers.get_column_types(arr)]
|
||||
numpy_tables_helpers.get_column_types(arr)]
|
||||
actual = '\n'.join(actual)
|
||||
read_expected_from_file_and_compare_with_actual(
|
||||
actual=actual,
|
||||
expected_file=file
|
||||
)
|
||||
|
||||
def _get_python_version_info():
|
||||
# () -> str
|
||||
return str(sys.version_info[0]) + '_' + str(sys.version_info[1])
|
||||
|
||||
|
||||
def test_simple_array():
|
||||
arr = np.array([1, 2, 3])
|
||||
check_info_np_array(arr, 'test_data/numpy/simple_np_array_after.txt')
|
||||
exp_file_python_ver = _get_python_version_info()
|
||||
check_info_np_array(arr, 'test_data/numpy/simple_np_array_' + exp_file_python_ver + '_after.txt')
|
||||
|
||||
|
||||
def test_simple_2d_array():
|
||||
arr = np.array([[True, "False", True], [True, True, False]])
|
||||
check_info_np_array(arr, 'test_data/numpy/simple_2d_np_array_after.txt')
|
||||
exp_file_python_ver = _get_python_version_info()
|
||||
check_info_np_array(arr, 'test_data/numpy/simple_2d_np_array_' + exp_file_python_ver + '_after.txt')
|
||||
|
||||
|
||||
def test_2d_array():
|
||||
arr = np.array([[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
[7, 8, 9]])
|
||||
check_info_np_array(arr, 'test_data/numpy/2d_np_array_after.txt')
|
||||
exp_file_python_ver = _get_python_version_info()
|
||||
check_info_np_array(arr, 'test_data/numpy/2d_np_array_' + exp_file_python_ver + '_after.txt')
|
||||
|
||||
|
||||
def test_array_with_dtype():
|
||||
@@ -45,7 +53,8 @@ def test_array_with_dtype():
|
||||
("cf", "f4"),
|
||||
("cs", "U16"),
|
||||
("cb", "?")])
|
||||
check_info_np_array(arr, 'test_data/numpy/np_array_with_dtype_after.txt')
|
||||
exp_file_python_ver = _get_python_version_info()
|
||||
check_info_np_array(arr, 'test_data/numpy/np_array_with_dtype_' + exp_file_python_ver + '_after.txt')
|
||||
|
||||
|
||||
def test_sorting_simple_array():
|
||||
@@ -98,17 +107,23 @@ def read_expected_from_file_and_compare_with_actual(actual, expected_file):
|
||||
with open(expected_file, 'r') as in_f:
|
||||
expected = in_f.read()
|
||||
|
||||
|
||||
print("expected: ", expected)
|
||||
print()
|
||||
print("actual: ", actual)
|
||||
# for a more convenient assertion fails messages here we compare string char by char
|
||||
for ind, (act, exp) in enumerate(zip(actual, expected)):
|
||||
assert act == exp, \
|
||||
("index is %s, act part = %s, exp part = %s" %
|
||||
("index is %s, act part = %s,\n\nexp part = %s" %
|
||||
(ind,
|
||||
actual[max(0, ind - 20): min(len(actual) - 1, ind + 20)],
|
||||
expected[max(0, ind - 20): min(len(actual) - 1, ind + 20)]))
|
||||
# actual[max(0, ind - 20): min(len(actual) - 1, ind + 20)],
|
||||
# expected[max(0, ind - 20): min(len(actual) - 1, ind + 20)]))
|
||||
actual,
|
||||
expected))
|
||||
|
||||
|
||||
def _sort_array(arr, cols, orders):
|
||||
return pandas_tables_helpers._NpTable(arr).sort((cols, orders))
|
||||
return numpy_tables_helpers._NpTable(arr).sort((cols, orders))
|
||||
|
||||
|
||||
def _is_equals(arr_a, arr_b):
|
||||
|
||||
@@ -48,7 +48,7 @@ def setup_dataframe():
|
||||
)
|
||||
df['datetime64[ns]'] = df['datetime64[ns]'].astype("datetime64[ns]")
|
||||
df['I'] = df['I'].astype("datetime64[ns]")
|
||||
df_html = repr(df.head().to_html(notebook=True, max_cols=None))
|
||||
df_html = repr(df.head(1).to_html(notebook=True, max_cols=None))
|
||||
columns_types = [str(df.index.dtype)] + [str(t) for t in df.dtypes]
|
||||
|
||||
return rows_number, df, df_html, columns_types
|
||||
@@ -112,7 +112,7 @@ def test_get_data_saves_display_options(setup_dataframe):
|
||||
max_colwidth_before = pd.get_option('display.max_colwidth')
|
||||
max_rows_before = pd.get_option('display.max_rows')
|
||||
|
||||
pandas_tables_helpers.get_data(df)
|
||||
pandas_tables_helpers.get_data(df, False)
|
||||
|
||||
max_columns_after = pd.get_option('display.max_columns')
|
||||
max_colwidth_after = pd.get_option('display.max_colwidth')
|
||||
@@ -134,7 +134,7 @@ def test_display_saves_display_options(setup_dataframe):
|
||||
max_colwidth_before = pd.get_option('display.max_colwidth')
|
||||
max_rows_before = pd.get_option('display.max_rows')
|
||||
|
||||
pandas_tables_helpers.display_data(df, start_index=0, end_index=2)
|
||||
pandas_tables_helpers.display_data_html(df, start_index=0, end_index=2)
|
||||
|
||||
max_columns_after = pd.get_option('display.max_columns')
|
||||
max_colwidth_after = pd.get_option('display.max_colwidth')
|
||||
@@ -184,6 +184,7 @@ def test_get_info_format(setup_dataframe):
|
||||
print('$NEXT_VALUE_SEPARATOR')
|
||||
print(get_head(initCommandResult))
|
||||
print('$NEXT_VALUE_SEPARATOR')
|
||||
print('$NEXT_VALUE_SEPARATOR')
|
||||
print(get_column_types(initCommandResult))
|
||||
|
||||
Here we check that with pandas_tables_helpers methods can compose expected result
|
||||
@@ -206,6 +207,13 @@ def test_get_info_format(setup_dataframe):
|
||||
pandas_tables_helpers.get_column_types(df)]
|
||||
actual = '\n'.join(actual)
|
||||
|
||||
print("GET INFO: START")
|
||||
print()
|
||||
pandas_tables_helpers.get_head(df)
|
||||
print()
|
||||
print("GET INFO: END")
|
||||
print()
|
||||
|
||||
read_expected_from_file_and_compare_with_actual(
|
||||
actual=actual,
|
||||
expected_file='test_data/pandas/getInfo_result.txt'
|
||||
|
||||
@@ -1,25 +1,59 @@
|
||||
[tox]
|
||||
envlist = python2.7, python3.8, python3.9, numpy_only2.7, numpy_only3.8, numpy_only3.9
|
||||
envlist = python2.7, python3.8, python3.12, no_pandas_python2.7, no_pandas_python3.8, no_pandas_python3.12
|
||||
isolated_build = True
|
||||
skipsdist = True
|
||||
|
||||
[testenv]
|
||||
[testenv:python2.7]
|
||||
deps =
|
||||
pytest
|
||||
teamcity-messages
|
||||
python2.7: pandas
|
||||
python3.8: pandas
|
||||
python3.9: pandas
|
||||
ipython
|
||||
python3.8: polars
|
||||
python3.9: polars
|
||||
numpy
|
||||
pandas
|
||||
commands = pytest -s test_pydev_pandas.py test_ds_sorting_commands/test_pandas.py
|
||||
|
||||
[testenv:numpy_only{2.7,3.8,3.9}]
|
||||
[testenv:python3.8]
|
||||
deps =
|
||||
pytest
|
||||
numpy
|
||||
teamcity-messages
|
||||
ipython
|
||||
numpy
|
||||
pandas
|
||||
polars
|
||||
commands = pytest -s test_pydev_pandas.py test_ds_sorting_commands/test_pandas.py
|
||||
|
||||
[testenv:python3.12]
|
||||
deps =
|
||||
pytest
|
||||
teamcity-messages
|
||||
ipython
|
||||
numpy
|
||||
pandas
|
||||
polars
|
||||
commands = pytest -s test_pydev_pandas.py test_ds_sorting_commands/test_pandas.py
|
||||
|
||||
[testenv:no_pandas_python2.7]
|
||||
deps =
|
||||
pytest
|
||||
teamcity-messages
|
||||
ipython
|
||||
numpy
|
||||
commands = pytest -s test_pydev_nparray.py
|
||||
|
||||
[testenv:no_pandas_python3.8]
|
||||
deps =
|
||||
pytest
|
||||
teamcity-messages
|
||||
ipython
|
||||
numpy
|
||||
commands = pytest -s test_pydev_nparray.py
|
||||
|
||||
[testenv:no_pandas_python3.12]
|
||||
deps =
|
||||
pytest
|
||||
teamcity-messages
|
||||
ipython
|
||||
numpy
|
||||
commands = pytest -s test_pydev_nparray.py
|
||||
|
||||
setenv = PYTHONPATH = {toxinidir}/../third_party/thriftpy
|
||||
|
||||
Reference in New Issue
Block a user