Dictionary-like objects and pandas dataframe

603 views
Skip to first unread message

SuperGeo

unread,
Jan 25, 2018, 1:17:58 PM1/25/18
to robotframework-users
Hi,

I have a function that returns a pandas DataFrame (a group of signals), from which we can get subsets by using df["signal1"], just like a dictionary.

However, on Robot Framework I tried using:

${DF} =    |    func that returns dataframe
Use df     |    &{DF}[$signal1]

but I get:

Value of variable '&{DF}' is not dictionary or dictionary-like.

So I was wondering what is meant by dictionary-like, as a dataframe surely implements __getitem__ interface.

Thanks!

Hélio Guilherme

unread,
Jan 25, 2018, 1:46:30 PM1/25/18
to robotframework-users
Try using like this:
&{DF} =    |    func that returns dataframe
Use df     |    ${DF}[$signal1]

The '&' should only be used for the creation or assignment.

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.
To post to this group, send email to robotframework-users@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.



--
My Favorite Open Source Projects
awsome-lists gretl meld robotframework wxPython

Pekka Klärck

unread,
Jan 25, 2018, 3:19:44 PM1/25/18
to Victor Maryama, robotframework-users
Dictionary variables need to implement collections.Mapping. Do you think that should be changed? Considering any object with just __getitem__ to be a dictionary sounds a bit strange for me.

Sent from my mobile.

Victor Maryama

unread,
Jan 26, 2018, 3:09:26 AM1/26/18
to Pekka Klärck, robotframework-users
@Helio:

Thanks for the tip! But anyways I get:

>>> Cannot set variable '&{DF}': Expected dictionary-like value, got DataFrame.

@Pekka

I see. If Robot Framework should type-check (strong typing) then you are probably correct. But if we just do duck-typing as usual in Python, then we could just let the user try to use any objects as if they were dicts and see what breaks depending on the type of operation implemented.

In this case, certainly we could use the notation ${object}[$key] as, for this particular use of sintax, it does act like a dict. So maybe for other cases it won't, but then we would just have an exception as any other I guess.


2018-01-25 21:19 GMT+01:00 Pekka Klärck <pekka....@gmail.com>:
Dictionary variables need to implement collections.Mapping. Do you think that should be changed? Considering any object with just __getitem__ to be a dictionary sounds a bit strange for me.

Sent from my mobile.
25.1.2018 20.18 "SuperGeo" <victor....@gmail.com> kirjoitti:
Hi,

I have a function that returns a pandas DataFrame (a group of signals), from which we can get subsets by using df["signal1"], just like a dictionary.

However, on Robot Framework I tried using:

${DF} =    |    func that returns dataframe
Use df     |    &{DF}[$signal1]

but I get:

Value of variable '&{DF}' is not dictionary or dictionary-like.

So I was wondering what is meant by dictionary-like, as a dataframe surely implements __getitem__ interface.

Thanks!

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsubscrib...@googlegroups.com.

Victor Maryama

unread,
Jan 26, 2018, 3:13:34 AM1/26/18
to Pekka Klärck, robotframework-users
Oh, forgot to mention (just for the record) that I worked around this using:

>>> ${DF.get('signal')}

Pekka Klärck

unread,
Jan 31, 2018, 6:04:08 PM1/31/18
to Victor Maryama, robotframework-users
2018-01-26 10:09 GMT+02:00 Victor Maryama <victor....@gmail.com>:
>
> @Pekka
>
> I see. If Robot Framework should type-check (strong typing) then you are
> probably correct. But if we just do duck-typing as usual in Python, then we
> could just let the user try to use any objects as if they were dicts and see
> what breaks depending on the type of operation implemented.

I kind of agree with this, but then again also lists have __getitem__
(and are iterable). Considering lists to be dictionaries sounds wrong
to me.

I'm somewhat surprised this object doesn't implement
collections.Mapping if it really is a mapping. One thing you could do
is implementing an proxy that implements collections.Mapping (you only
need to implement __getitem__, __iter__ and __len__) and delegates to
the underlying object.

Cheers,
.peke
Reply all
Reply to author
Forward
0 new messages