def test_dicts_natural_sorting_mixed_types(): """ Test that natural sorting actually does what it should do. testing for issue 13733, as mixed types were sorted incorrectly. Sorting for other columns will be tested as well. """ import pandas as pd dictionary = { 'DSeries': pd.Series(dtype=int), 'aStr': 'algName', 'kDict': { 2: 'asd', 3: 2 } } # put this here variable, as it might change later to reflect string length str_size = get_size(dictionary['aStr']) editor = CollectionsEditor() editor.setup(dictionary) cm = editor.widget.editor.source_model cm.sort(0) keys = cm.keys types = cm.types sizes = cm.sizes assert keys == ['aStr', 'DSeries', 'kDict'] assert types == ['str', 'Series', 'dict'] assert sizes == [str_size, (0, ), 2] assert data_table(cm, 3, 3) == [['aStr', 'DSeries', 'kDict'], ['str', 'Series', 'dict'], [str_size, '(0,)', 2]] # insert an item and check that it is still sorted correctly editor.widget.editor.new_value('List', [1, 2, 3]) assert data_table(cm, 4, 3) == [['aStr', 'DSeries', 'kDict', 'List'], ['str', 'Series', 'dict', 'list'], [str_size, '(0,)', 2, 3]] cm.sort(0) assert data_table(cm, 4, 3) == [['aStr', 'DSeries', 'kDict', 'List'], ['str', 'Series', 'dict', 'list'], [str_size, '(0,)', 2, 3]] # now sort for types cm.sort(1) assert data_table(cm, 4, 3) == [['DSeries', 'kDict', 'List', 'aStr'], ['Series', 'dict', 'list', 'str'], ['(0,)', 2, 3, str_size]] # now sort for sizes cm.sort(2) assert data_table(cm, 4, 3) == [['DSeries', 'kDict', 'List', 'aStr'], ['Series', 'dict', 'list', 'str'], ['(0,)', 2, 3, str_size]]
def test_get_size(): """Test that the size of all values is returned correctly""" class RecursionClassNoLen(): def __getattr__(self, name): if name == 'size': return self.name else: return super(object, self).__getattribute__(name) length = [ list([1, 2, 3]), tuple([1, 2, 3]), set([1, 2, 3]), '123', { 1: 1, 2: 2, 3: 3 } ] for obj in length: assert get_size(obj) == 3 df = pd.DataFrame([[1, 2, 3], [1, 2, 3]]) assert get_size(df) == (2, 3) df = pd.Series([1, 2, 3]) assert get_size(df) == (3, ) df = pd.Index([1, 2, 3]) assert get_size(df) == (3, ) arr = np.array([[1, 2, 3], [1, 2, 3]], dtype=np.complex) assert get_size(arr) == (2, 3) img = PIL.Image.new('RGB', (256, 256)) assert get_size(img) == (256, 256) obj = RecursionClassNoLen() assert get_size(obj) == 1
doc=_("Type of the object determined using the builtin type() function"), data_fn=lambda tree_item: str(type(tree_item.obj)), col_visible=False, width=MEDIUM_COL_WIDTH) ATTR_MODEL_CLASS = AttributeModel( 'Type', doc="The name of the class of the object via obj.__class__.__name__", data_fn=lambda tree_item: get_human_readable_type(tree_item.obj), col_visible=True, width=MEDIUM_COL_WIDTH) ATTR_MODEL_LENGTH = AttributeModel( 'Size', doc=_("The length or shape of the object"), data_fn=lambda tree_item: to_text_string(get_size(tree_item.obj)), col_visible=True, alignment=ALIGN_RIGHT, width=SMALL_COL_WIDTH) ATTR_MODEL_ID = AttributeModel( 'Id', doc=_("The identifier of the object with " "calculated using the id() function"), data_fn=lambda tree_item: "0x{:X}".format(id(tree_item.obj)), col_visible=False, alignment=ALIGN_RIGHT, width=SMALL_COL_WIDTH) ATTR_MODEL_IS_ATTRIBUTE = AttributeModel( 'Attribute',