def test_building_attribute_dataframe_with_a_single_key_list_input(): df = graph_operations.build_attribute_dataframe([('1', { 'key': 1, 'another_key': 2 }), ('2', { 'key': 3 })], keys=['key']) assert_frame_equal(df, DataFrame({'key': {'1': 1, '2': 3}}))
def test_building_attribute_dataframe_with_multiple_keys_and_missing_value(): df = graph_operations.build_attribute_dataframe( [('1', { 'key': 1, 'another_key': 2 }), ('2', { 'key': 3 })], keys=['key', 'another_key']) assert_frame_equal( df, DataFrame({ 'key': { '1': 1, '2': 3 }, 'another_key': { '1': 2.0, '2': float('nan') } }))
def test_building_attribute_dataframe_with_multiple_keys_and_iterator(): data = [('1', { 'key': 1, 'another_key': 2 }), ('2', { 'key': 3, 'another_key': 11 })] df = graph_operations.build_attribute_dataframe( iterate(data), keys=['key', 'another_key']) assert_frame_equal( df, DataFrame({ 'key': { '1': 1, '2': 3 }, 'another_key': { '1': 2, '2': 11 } }))
def test_building_attribute_dataframe_with_multiple_keys_and_index_name(): df = graph_operations.build_attribute_dataframe( [('1', { 'key': 1, 'another_key': 2 }), ('2', { 'key': 3, 'another_key': 11 })], keys=['key', 'another_key'], index_name='nameee') correct_df = DataFrame({ 'key': { '1': 1, '2': 3 }, 'another_key': { '1': 2, '2': 11 } }) correct_df.index = df.index.set_names(['nameee']) assert_frame_equal(df, correct_df)