21

I have ggplot successfully installed in my python 3.6.3 using the code below:

conda install -c conda-forge ggplot 

But when I import it in my notebook using the code below, I get an error:

from ggplot import *
ImportError: cannot import name 'Timestamp'

I would appreciate any idea on how I can solve this problem.

Krantz
  • 1,424
  • 1
  • 12
  • 31

5 Answers5

62

I have encountered the same problem.

Please go to .../site-packages/ggplot/stats/smoothers.py and change

from pandas.lib import Timestamp

to

from pandas import Timestamp

and save.

liaoming999
  • 769
  • 8
  • 14
  • 1
    can you do this from a Jupyter notebook? I'm on a shared server and I don't have access to those directories. By the way, did something _just_ happen to cause this? I imported ggplot on the same server yesterday with no problem, and now I notice this question is only 1 day old... – seth127 May 30 '18 at 19:21
  • 1
    hi, my best guest for your situation is that someone upgrades the pandas package in the sever which causes Timestamp is deprecated from pandas.lib and the resulting error. I can only come up with two solutions: 1. use virtualenv package to create your own environment so that you can have access to those directories; 2. downgrade the pandas package to a suitable version(not quite sure) – liaoming999 May 31 '18 at 08:08
15

@Liaoming999 is correct but adding more changes to resolve this problem:

  1. Open file ../site-packages/ggplot/stats/smoothers.py
  2. Change from pandas.lib import Timestamp to from pandas import Timestamp in line 4
  3. Change pd.tslib.Timestamp to pd.Timestamp in line 14.
  4. Save the file
  5. Open file ../site-packages/ggplot/utils.py and goto line 81 and do the same as step 3. Thanks to @wmsmith for this tip.

p.s.: General advise is to use Anaconda or some Virtual env.

Srikar Appalaraju
  • 71,928
  • 54
  • 216
  • 264
  • I just finished a fresh install on a brand new imac. Apparently, this same thing must be done in ../site-packages/ggplot/utils.py as well. So after updating stats/smoothers.py and utils.py ggplot could finally be imported. – wmsmith Jun 10 '19 at 23:11
5

I encountered the same problem after upgrading to pandas 0.23 on a databricks server.

Had to come up with this command-line solution using the unix sed tool:

cd .../python/lib/python3.5/site-packages/ggplot/stats/
sed -i 's/pandas.lib/pandas/g' smoothers.py
dportman
  • 1,101
  • 10
  • 20
4

I completely agree with @Srikar Appalaraju. Additionally, update the line 81 in utils.py (path is .../site-packages/ggplot/utils.py) from "pd.tslib.Timestamp" to "pd.Timestamp" to remove FutureWarning.

Ajeet Mishra
  • 342
  • 2
  • 8
2

There has been little going on for a while in ggplot - maybe it'll change in the future, and the main project comes around.

In the meantime, instead of hacking the library (which is sometimes hard), you can use this friendly fork:

https://github.com/sushinoya/ggpy

Further reading: https://github.com/yhat/ggpy/issues/654

Install using:

pip install git+https://github.com/sushinoya/ggpy

or:

pip install --user git+https://github.com/sushinoya/ggpy

(the latter may work in a shared server environment)

Caveats: you'll need Git, and maybe a working compiler for Python extensions.

Tomasz Gandor
  • 8,235
  • 2
  • 60
  • 55