Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Add to_dict SFrame method #2755

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dhivyaaxim
Copy link
Contributor

This PR resolves #1909
Add a to_dict method on SFrame

for key in self.column_names():
sa = SArray(self[key])
val_list = []
for val in sa:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm; Pandas actually seems to behave a bit differently. I'm not sure why but it gives dictionaries of dictionaries (where the inner dictionaries have numeric keys ranging from 0 to n for n rows), instead of dictionaries of lists. I suspect this is to better handle sparse dataframes? Example of this behavior:

In [23]: d = df.to_dict()

In [24]: type(d)
Out[24]: dict

In [25]: d.keys()
Out[25]: ['path', 'image']

In [26]: type(d['path'])
Out[26]: dict

In [27]: d['path'].keys()
Out[27]: 
[0,
 1,
 2,
...

In any case, we should probably preserve the same behavior here -- let's use a dict instead of a list for the inner structure, using row index as the key.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand pandas' behavior here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pandas always gives a sparse representation (even if the original data was dense) -- i.e. using dictionaries instead of lists, with row index as the dictionary key.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@znation - what do you recommend we do here? Should we modify this pull so we match pandas' behavior? Should we close the issue (#1909) as will not fix?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I have an opinion on this one. I am not a fan of Pandas behavior here, but the goal of #1909 was to match Pandas behavior.

@TobyRoseman TobyRoseman changed the title Issue_1909_Add_a_to_dict_method_on_SFrame Add to_dict SFrame method Jan 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a to_dict method on SFrame
4 participants