mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
PY-73641 ... in tables instead of values
* added setter option for max_rows GitOrigin-RevId: 3cedda6ac4e9aa4dfcb0bda80111198bf8341e0a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
873b88a98f
commit
f721a69556
@@ -54,13 +54,15 @@ def __get_data_slice(table, start, end):
|
||||
|
||||
|
||||
def _compute_sliced_data(table, fun, start_index=None, end_index=None):
|
||||
max_cols, max_colwidth = __get_tables_display_options()
|
||||
max_cols, max_colwidth, max_rows = __get_tables_display_options()
|
||||
|
||||
_jb_max_cols = pd.get_option('display.max_columns')
|
||||
_jb_max_colwidth = pd.get_option('display.max_colwidth')
|
||||
_jb_max_rows = pd.get_option('display.max_rows')
|
||||
|
||||
pd.set_option('display.max_columns', max_cols)
|
||||
pd.set_option('display.max_colwidth', max_colwidth)
|
||||
pd.set_option('display.max_rows', max_rows)
|
||||
|
||||
if start_index is not None and end_index is not None:
|
||||
table = __get_data_slice(table, start_index, end_index)
|
||||
@@ -71,6 +73,7 @@ def _compute_sliced_data(table, fun, start_index=None, end_index=None):
|
||||
|
||||
pd.set_option('display.max_columns', _jb_max_cols)
|
||||
pd.set_option('display.max_colwidth', _jb_max_colwidth)
|
||||
pd.set_option('display.max_rows', _jb_max_rows)
|
||||
|
||||
return data
|
||||
|
||||
@@ -79,8 +82,8 @@ def _compute_sliced_data(table, fun, start_index=None, end_index=None):
|
||||
def __get_tables_display_options():
|
||||
import sys
|
||||
if sys.version_info < (3, 0):
|
||||
return None, MAX_COLWIDTH_PYTHON_2
|
||||
return None, None
|
||||
return None, MAX_COLWIDTH_PYTHON_2, None
|
||||
return None, None, None
|
||||
|
||||
|
||||
# noinspection PyUnresolvedReferences
|
||||
|
||||
@@ -242,9 +242,9 @@ def _compute_data(arr, fun):
|
||||
is_sort_command = type(arr) is dict
|
||||
data = arr['data'] if is_sort_command else arr
|
||||
|
||||
jb_max_cols, jb_max_colwidth = None, None
|
||||
jb_max_cols, jb_max_colwidth, jb_max_rows = None, None, None
|
||||
if is_pd:
|
||||
jb_max_cols, jb_max_colwidth = _set_pd_options()
|
||||
jb_max_cols, jb_max_colwidth, jb_max_rows = _set_pd_options()
|
||||
|
||||
if is_sort_command:
|
||||
arr['data'] = data
|
||||
@@ -253,31 +253,34 @@ def _compute_data(arr, fun):
|
||||
data = fun(data, None)
|
||||
|
||||
if is_pd:
|
||||
_reset_pd_options(jb_max_cols, jb_max_colwidth)
|
||||
_reset_pd_options(jb_max_cols, jb_max_colwidth, jb_max_rows)
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def __get_tables_display_options():
|
||||
# type: () -> Tuple[None, Union[int, None]]
|
||||
# type: () -> Tuple[None, Union[int, None], None]
|
||||
import sys
|
||||
if sys.version_info < (3, 0):
|
||||
return None, MAX_COLWIDTH
|
||||
return None, None
|
||||
return None, MAX_COLWIDTH, None
|
||||
return None, None, None
|
||||
|
||||
|
||||
def _set_pd_options():
|
||||
max_cols, max_colwidth = __get_tables_display_options()
|
||||
max_cols, max_colwidth, max_rows = __get_tables_display_options()
|
||||
|
||||
_jb_max_cols = pd.get_option('display.max_columns')
|
||||
_jb_max_colwidth = pd.get_option('display.max_colwidth')
|
||||
_jb_max_rows = pd.get_option('display.max_rows')
|
||||
|
||||
pd.set_option('display.max_columns', max_cols)
|
||||
pd.set_option('display.max_colwidth', max_colwidth)
|
||||
pd.set_option('display.max_rows', max_rows)
|
||||
|
||||
return _jb_max_cols, _jb_max_colwidth
|
||||
return _jb_max_cols, _jb_max_colwidth, _jb_max_rows
|
||||
|
||||
|
||||
def _reset_pd_options(max_cols, max_colwidth):
|
||||
def _reset_pd_options(max_cols, max_colwidth, max_rows):
|
||||
pd.set_option('display.max_columns', max_cols)
|
||||
pd.set_option('display.max_colwidth', max_colwidth)
|
||||
pd.set_option('display.max_rows', max_rows)
|
||||
|
||||
@@ -61,13 +61,15 @@ def __get_data_slice(table, start, end):
|
||||
def _compute_sliced_data(table, fun, start_index=None, end_index=None):
|
||||
# type: (Union[pd.DataFrame, pd.Series], function, int, int) -> str
|
||||
|
||||
max_cols, max_colwidth = __get_tables_display_options()
|
||||
max_cols, max_colwidth, max_rows = __get_tables_display_options()
|
||||
|
||||
_jb_max_cols = pd.get_option('display.max_columns')
|
||||
_jb_max_colwidth = pd.get_option('display.max_colwidth')
|
||||
_jb_max_rows = pd.get_option('display.max_rows')
|
||||
|
||||
pd.set_option('display.max_columns', max_cols)
|
||||
pd.set_option('display.max_colwidth', max_colwidth)
|
||||
pd.set_option('display.max_rows', max_rows)
|
||||
|
||||
if start_index is not None and end_index is not None:
|
||||
table = __get_data_slice(table, start_index, end_index)
|
||||
@@ -76,6 +78,7 @@ def _compute_sliced_data(table, fun, start_index=None, end_index=None):
|
||||
|
||||
pd.set_option('display.max_columns', _jb_max_cols)
|
||||
pd.set_option('display.max_colwidth', _jb_max_colwidth)
|
||||
pd.set_option('display.max_rows', _jb_max_rows)
|
||||
|
||||
return data
|
||||
|
||||
@@ -251,8 +254,8 @@ def __categorical_to_df(table):
|
||||
|
||||
# In old versions of pandas max_colwidth accepted only Int-s
|
||||
def __get_tables_display_options():
|
||||
# type: () -> Tuple[None, Union[int, None]]
|
||||
# type: () -> Tuple[None, Union[int, None], None]
|
||||
import sys
|
||||
if sys.version_info < (3, 0):
|
||||
return None, MAX_COLWIDTH_PYTHON_2
|
||||
return None, None
|
||||
return None, MAX_COLWIDTH_PYTHON_2, None
|
||||
return None, None, None
|
||||
|
||||
@@ -110,14 +110,17 @@ def test_get_data_saves_display_options(setup_dataframe):
|
||||
|
||||
max_columns_before = pd.get_option('display.max_columns')
|
||||
max_colwidth_before = pd.get_option('display.max_colwidth')
|
||||
max_rows_before = pd.get_option('display.max_rows')
|
||||
|
||||
pandas_tables_helpers.get_data(df)
|
||||
|
||||
max_columns_after = pd.get_option('display.max_columns')
|
||||
max_colwidth_after = pd.get_option('display.max_colwidth')
|
||||
max_rows_after = pd.get_option('display.max_rows')
|
||||
|
||||
assert max_columns_before == max_columns_after
|
||||
assert max_colwidth_before == max_colwidth_after
|
||||
assert max_rows_before == max_rows_after
|
||||
|
||||
|
||||
def test_display_saves_display_options(setup_dataframe):
|
||||
@@ -129,14 +132,17 @@ def test_display_saves_display_options(setup_dataframe):
|
||||
|
||||
max_columns_before = pd.get_option('display.max_columns')
|
||||
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)
|
||||
|
||||
max_columns_after = pd.get_option('display.max_columns')
|
||||
max_colwidth_after = pd.get_option('display.max_colwidth')
|
||||
max_rows_after = pd.get_option('display.max_rows')
|
||||
|
||||
assert max_columns_before == max_columns_after
|
||||
assert max_colwidth_before == max_colwidth_after
|
||||
assert max_rows_before == max_rows_after
|
||||
|
||||
|
||||
def test_convert_to_df_unnamed_series(setup_series_no_names):
|
||||
|
||||
Reference in New Issue
Block a user