Getting memory address of dataframe/series?

582 views
Skip to first unread message

Adam Hughes

unread,
Sep 7, 2014, 7:33:44 PM9/7/14
to pyd...@googlegroups.com
Hi, 

This is probably a dumb question, but is it possible to return the memory address of a pandas DataFrame?  I'm working on some stuff where I need to constantly test if frames are being passed by reference or object are being created new, and this would help.  In the past, for classes that inherit from python's object class, I could just hack super's __repr__ because python's object class by default prints the memory address.  I was wondering if there was a straightforward way to do the same for frames.

Jeff Reback

unread,
Sep 7, 2014, 7:37:20 PM9/7/14
to pyd...@googlegroups.com
you can check id(df)
and compare that - it's unique for every object

On Sep 7, 2014, at 7:33 PM, Adam Hughes <hughes...@gmail.com> wrote:

Hi, 

This is probably a dumb question, but is it possible to return the memory address of a pandas DataFrame?  I'm working on some stuff where I need to constantly test if frames are being passed by reference or object are being created new, and this would help.  In the past, for classes that inherit from python's object class, I could just hack super's __repr__ because python's object class by default prints the memory address.  I was wondering if there was a straightforward way to do the same for frames.

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

Jeffrey Tratner

unread,
Sep 7, 2014, 7:46:58 PM9/7/14
to pyd...@googlegroups.com
As an addendum, you can also check with `df1 is df2` which will only be true for reference equality

Adam Hughes

unread,
Sep 7, 2014, 8:03:43 PM9/7/14
to pyd...@googlegroups.com
Thanks, Jeff and Jeff!

I will use the id, I forgot about that.

Jeffrey, good point, but for my needs, it's easier to put this in __repr__ so I can avoid the constant need to do just that in my debugging.

Achyutananda Sahoo

unread,
Jun 23, 2015, 3:25:17 AM6/23/15
to pyd...@googlegroups.com
Hi Adam & Jeff,
Please Guys i am facing same problem here. I want to use one single
DataFrame memory address by multiple process so that i don't have to use x
time dataframe for x number of process. Is that possible , If possible
please guys give me a way to do and kindly if you give me one Example
that would be better.I am waiting for your response.

Thanks,
Achyutananda Sahoo

Goyo

unread,
Jun 23, 2015, 5:23:07 AM6/23/15
to pyd...@googlegroups.com, achyutana...@ramyamlab.com

Python (the language) does not deal with memory addresses and I fail to understand why you might need them. That said, the id() function in CPython happens to return the object's memory address. But that is a CPython implementation detail and I do not think you should rely on it.

https://docs.python.org/3/library/functions.html#id

Goyo

Nathaniel Smith

unread,
Jun 23, 2015, 5:30:18 AM6/23/15
to pyd...@googlegroups.com
If you're on OS X or Linux, then I think your best hope would be to
load your data frame once in a parent process, and then use os.fork
(perhaps via the multiprocessing module) to spawn several child
processes that "inherit" the already-loaded data frame from the
parent. This approach is somewhat fragile, has a number of
limitations, and requires some understanding of system-level details
like copy-on-write and virtual memory, but it can be very effective in
the right situation, and hopefully it at least gives you a clue to
follow up on.

-n

--
Nathaniel J. Smith -- http://vorpus.org

Achyuta nanda sahoo

unread,
Jun 23, 2015, 11:28:15 AM6/23/15
to pyd...@googlegroups.com
Hi Adam & Jeff,
   Please Guys i am facing same problem here. I want to use one single DataFrame memory address by multiple process so that i don't have to use x time dataframe for x number of process. Is that possible , If possible please guys give me a way to do  and kindly if you give me one Example that would be better.I am waiting for your response.

Thanks,
Achyutananda Sahoo
Reply all
Reply to author
Forward
0 new messages