Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: module 'pandas' has no attribute 'tslib' #662

Open
mmellor1 opened this issue Apr 11, 2019 · 35 comments
Open

AttributeError: module 'pandas' has no attribute 'tslib' #662

mmellor1 opened this issue Apr 11, 2019 · 35 comments

Comments

@mmellor1
Copy link

No description provided.

@mmellor1
Copy link
Author

I just installed ggplot on my Windows computer running Python 3.7 using pip. When I try to run:

"import pandas as pd
from ggplot import *"

I get the error: "AttributeError: module 'pandas' has no attribute 'tslib'"

Here is the traceback:
Traceback (most recent call last):
File ".\TIR_parser.py", line 73, in
from ggplot import *
File "C:\Program Files\Python37\lib\site-packages\ggplot_init_.py", line 19, in
from .geoms import geom_area, geom_blank, geom_boxplot, geom_line, geom_point, geom_jitter, geom_histogram, geom_density, geom_hline, geom_vline, geom_bar, geom_abline, geom_tile, geom_rect, geom_bin2d, geom_step, geom_text, geom_path, geom_ribbon, geom_now_its_art, geom_violin, geom_errorbar, geom_polygon
File "C:\Program Files\Python37\lib\site-packages\ggplot\geoms_init_.py", line 1, in
from .geom_abline import geom_abline
File "C:\Program Files\Python37\lib\site-packages\ggplot\geoms\geom_abline.py", line 1, in
from .geom import geom
File "C:\Program Files\Python37\lib\site-packages\ggplot\geoms\geom.py", line 3, in
from ..ggplot import ggplot
File "C:\Program Files\Python37\lib\site-packages\ggplot\ggplot.py", line 13, in
from .aes import aes
File "C:\Program Files\Python37\lib\site-packages\ggplot\aes.py", line 11, in
from . import utils
File "C:\Program Files\Python37\lib\site-packages\ggplot\utils.py", line 81, in
pd.tslib.Timestamp,
AttributeError: module 'pandas' has no attribute 'tslib'

@mmellor1 mmellor1 reopened this Apr 11, 2019
@novostavsky
Copy link

the same error after installation ggplot. Tried to uninstall pandas and lower version to 0.23.* - didn't help
Microsoft Windows [Version 10.0.17763.379]
Python 3.7.2

pip freeze
..
pandas==0.24.2
tslib==1.6
ggplot==0.11.5
..

>>> import ggplot Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\Volodymyr_Novostavsk\AppData\Roaming\Python\Python37\site-packages\ggplot\__init__.py", line 19, in <module> from .geoms import geom_area, geom_blank, geom_boxplot, geom_line, geom_point, geom_jitter, geom_histogram, geom_density, geom_hline, geom_vline, geom_bar, geom_abline, geom_tile, geom_rect, geom_bin2d, geom_step, geom_text, geom_path, geom_ribbon, geom_now_its_art, geom_violin, geom_errorbar, geom_polygon File "C:\Users\Volodymyr_Novostavsk\AppData\Roaming\Python\Python37\site-packages\ggplot\geoms\__init__.py", line 1, in <module> from .geom_abline import geom_abline File "C:\Users\Volodymyr_Novostavsk\AppData\Roaming\Python\Python37\site-packages\ggplot\geoms\geom_abline.py", line 1, in <module> from .geom import geom File "C:\Users\Volodymyr_Novostavsk\AppData\Roaming\Python\Python37\site-packages\ggplot\geoms\geom.py", line 3, in <module> from ..ggplot import ggplot File "C:\Users\Volodymyr_Novostavsk\AppData\Roaming\Python\Python37\site-packages\ggplot\ggplot.py", line 13, in <module> from .aes import aes File "C:\Users\Volodymyr_Novostavsk\AppData\Roaming\Python\Python37\site-packages\ggplot\aes.py", line 11, in <module> from . import utils File "C:\Users\Volodymyr_Novostavsk\AppData\Roaming\Python\Python37\site-packages\ggplot\utils.py", line 81, in <module> pd.tslib.Timestamp, AttributeError: module 'pandas' has no attribute 'tslib'

@mabu-dev
Copy link

Is there no fix to this issue?

@Aycrazy
Copy link

Aycrazy commented Apr 17, 2019

I assume we can change
pd.tslib.Timestamp to pd.Timestamp in the source file

@Aycrazy
Copy link

Aycrazy commented Apr 17, 2019

in the ggplot/utils.py file

change

date_types = (
    pd.tslib.Timestamp,
    pd.DatetimeIndex,
    pd.Period,
    pd.PeriodIndex,
    datetime.datetime,
    datetime.time
)

to

date_types = (
    pd.Timestamp,
    pd.DatetimeIndex,
    pd.Period,
    pd.PeriodIndex,
    datetime.datetime,
    datetime.time
)

Then do the same in the ggplot/stats/smoothers.py file
AND
comment out

from pandas.lib import Timestamp

I haven't tested out the code yet to see if anything doesnt work, but it imported at least

@brianmackenna
Copy link

brianmackenna commented Apr 17, 2019

Thanks @Aycrazy it also allowed me to import. Slight typo on your fix

to

date_types = (
pd.tslib.Timestamp,
pd.DatetimeIndex,
pd.Period,
pd.PeriodIndex,
datetime.datetime,
datetime.time
)

@Aycrazy
Copy link

Aycrazy commented Apr 17, 2019

yes. Thanks. Should have proofread

@xunhuan-li
Copy link

Hi guys,
It seems the solutions only solve the problem in import but leads to other issues. For example, run the first example provided here: http://ggplot.yhathq.com/

from ggplot import *
ggplot(aes(x='date', y='beef'), data=meat) +
geom_line() +
stat_smooth(colour='blue', span=0.2)


NameError Traceback (most recent call last)
~/.local/lib/python3.6/site-packages/IPython/core/formatters.py in call(self, obj)
700 type_pprinters=self.type_printers,
701 deferred_pprinters=self.deferred_printers)
--> 702 printer.pretty(obj)
703 printer.flush()
704 return stream.getvalue()

~/.local/lib/python3.6/site-packages/IPython/lib/pretty.py in pretty(self, obj)
400 if cls is not object
401 and callable(cls.dict.get('repr')):
--> 402 return _repr_pprint(obj, self, cycle)
403
404 return _default_pprint(obj, self, cycle)

~/.local/lib/python3.6/site-packages/IPython/lib/pretty.py in repr_pprint(obj, p, cycle)
695 """A pprint that just redirects to the normal repr function."""
696 # Find newlines and replace them with p.break
()
--> 697 output = repr(obj)
698 for idx,output_line in enumerate(output.splitlines()):
699 if idx:

~/anaconda/envs/tf12/lib/python3.6/site-packages/ggplot/ggplot.py in repr(self)
114
115 def repr(self):
--> 116 self.make()
117 # this is nice for dev but not the best for "real"
118 if os.environ.get("GGPLOT_DEV"):

~/anaconda/envs/tf12/lib/python3.6/site-packages/ggplot/ggplot.py in make(self)
634 if kwargs==False:
635 continue
--> 636 layer.plot(ax, facetgroup, self._aes, **kwargs)
637
638 self.apply_limits()

~/anaconda/envs/tf12/lib/python3.6/site-packages/ggplot/stats/stat_smooth.py in plot(self, ax, data, _aes)
70
71 if method == "lm":
---> 72 x, y, y1, y2 = smoothers.lm(x, y, 1-level)
73 elif method == "ma":
74 x, y, y1, y2 = smoothers.mavg(x, y, window=window)

~/anaconda/envs/tf12/lib/python3.6/site-packages/ggplot/stats/smoothers.py in lm(x, y, alpha)
50
51 if x_is_date:
---> 52 x = [Timestamp.fromordinal(int(i)) for i in x]
53 return (x, fittedvalues, predict_mean_ci_low, predict_mean_ci_upp)
54

~/anaconda/envs/tf12/lib/python3.6/site-packages/ggplot/stats/smoothers.py in (.0)
50
51 if x_is_date:
---> 52 x = [Timestamp.fromordinal(int(i)) for i in x]
53 return (x, fittedvalues, predict_mean_ci_low, predict_mean_ci_upp)
54

NameError: name 'Timestamp' is not defined

@brianmackenna
Copy link

No comment on your specific issue but I was able to use it for some things but not for everything e.g. I can create scatter plots but not bar charts as per #152

@paulathomas
Copy link

There are two separate but similar problems. Both are in smoothers.py, the first is in line 4 'from pandas.lib import Timestamp' why this line isn't failing with pandas 0.24.2 s beyond me but it does mean the later attempts to use the imported function don't work. A possible correction to this is to remove the '.lib' from this line. I will clone, experiment, and get back. Given this import, the main installation problem identified by the OP should be fixed by changing line 14 'pd.tslib.Timestamp,' can be changed to 'Tiimestamp' again I'll clone, experiment, and get back.

ETA: it has certainly solved the installation problem against pandas v 0.24.2, will experiment with using smoothers and get back.

@paulathomas
Copy link

paulathomas commented May 12, 2019

And as far as I can tell those changes do the trick. For backward compatibility, it would be nice to know which version of pandas the reorganisation happened in so code can be written to cope with both situations.

Oh and just remembered there is a similar problem with utils.py a line 81. Also changed in my local version.

@userqin
Copy link

userqin commented May 15, 2019

AttributeError: module 'pandas' has no attribute 'tslib'
I got the same error on myu imac book. How to solve this issue ?

@SamuelMarks
Copy link

Just sent through a PR to fix this problem: #664

@AbshkPskr
Copy link

for temporary fix downgrade pandas to 0.19.2
!pip install pandas==0.19.2

@Munaze
Copy link

Munaze commented Aug 22, 2019

in the ggplot/utils.py file

change

date_types = (
    pd.tslib.Timestamp,
    pd.DatetimeIndex,
    pd.Period,
    pd.PeriodIndex,
    datetime.datetime,
    datetime.time
)

to

date_types = (
    pd.Timestamp,
    pd.DatetimeIndex,
    pd.Period,
    pd.PeriodIndex,
    datetime.datetime,
    datetime.time
)

Then do the same in the ggplot/stats/smoothers.py file
AND
comment out

from pandas.lib import Timestamp

I haven't tested out the code yet to see if anything doesnt work, but it imported at least

I did worked for me but had to do some chnages

in utils file
change
date_types = (
pd._tslib.Timestamp,
pd.DatetimeIndex,
pd.Period,
pd.PeriodIndex,
datetime.datetime,
datetime.time
)
instead of
date_types = (
pd.tslib.Timestamp,
pd.DatetimeIndex,
pd.Period,
pd.PeriodIndex,
datetime.datetime,
datetime.time
)

int stats/smoothers.py file
comment out ---> from pandas.lib import Timestamp
and
date_types = (
pd.Timestamp,
pd.DatetimeIndex,
pd.Period,
pd.PeriodIndex,
datetime.datetime,
datetime.time
)

instead of
date_types = (
pd.tslib.Timestamp,
pd.DatetimeIndex,
pd.Period,
pd.PeriodIndex,
datetime.datetime,
datetime.time
)

it should work fine

@mabu-dev
Copy link

mabu-dev commented Aug 28, 2019

Works like magic! Thanks dude. 👍

@idantene
Copy link

in the ggplot/utils.py file
change

date_types = (
    pd.tslib.Timestamp,
    pd.DatetimeIndex,
    pd.Period,
    pd.PeriodIndex,
    datetime.datetime,
    datetime.time
)

to

date_types = (
    pd.Timestamp,
    pd.DatetimeIndex,
    pd.Period,
    pd.PeriodIndex,
    datetime.datetime,
    datetime.time
)

Then do the same in the ggplot/stats/smoothers.py file
AND
comment out
from pandas.lib import Timestamp
I haven't tested out the code yet to see if anything doesnt work, but it imported at least

I did worked for me but had to do some chnages

in utils file
change
date_types = (
pd._tslib.Timestamp,
pd.DatetimeIndex,
pd.Period,
pd.PeriodIndex,
datetime.datetime,
datetime.time
)
instead of
date_types = (
pd.tslib.Timestamp,
pd.DatetimeIndex,
pd.Period,
pd.PeriodIndex,
datetime.datetime,
datetime.time
)

int stats/smoothers.py file
comment out ---> from pandas.lib import Timestamp
and
date_types = (
pd.Timestamp,
pd.DatetimeIndex,
pd.Period,
pd.PeriodIndex,
datetime.datetime,
datetime.time
)

instead of
date_types = (
pd.tslib.Timestamp,
pd.DatetimeIndex,
pd.Period,
pd.PeriodIndex,
datetime.datetime,
datetime.time
)

it should work fine

That should not work fine.
from pandas.lib import Timestamp means that Timestamp is used elsewhere in that file and will now be invalid. Not only that, but _tslib is meant as a private module and not for external use.
If it works - it's only because you're not using (by luck) the functions that use Timestamp.

The correct way should be:

  1. Change pandas.tslib.Timestamp to pandas.Timestamp
  2. Change from pandas.lib import Timestamp to from pandas import Timestamp.

@lindsayveazey
Copy link

The correct way should be:

1. Change `pandas.tslib.Timestamp` to `pandas.Timestamp` (in utils.py and stats/smoothers.py)

2. Change `from pandas.lib import Timestamp` to `from pandas import Timestamp`. (in smoothers.py)

^ This works beautifully.

@ekalosak
Copy link

ekalosak commented Jan 14, 2020

Can we merge this: #664 ? Seems like the simple import fix is the consensus solution?

@danjenson
Copy link

Fresh python 3.7.6 install and this fails. Second merging #664

@liaojiahui-r
Copy link

Issue still there... Python 3.8

0^0

@hnguyentt
Copy link

Issue still there... Python 3.8

0^0

The package ggplot has not been updated since 2016.

@Lucafi
Copy link

Lucafi commented May 15, 2020

And as far as I can tell those changes do the trick. For backward compatibility, it would be nice to know which version of pandas the reorganisation happened in so code can be written to cope with both situations.

Oh and just remembered there is a similar problem with utils.py a line 81. Also changed in my local version.

You're terrific!

@singkwan
Copy link

Any fix for this? Still an issue with pandas==1.0.4 and python 3.7

@hnguyentt
Copy link

hnguyentt commented Jun 15, 2020

Any fix for this? Still an issue with pandas==1.0.4 and python 3.7

You can self fix your local package after installation with the instruction from idantene and Aycrazy above because I saw the master branch hasn't updated since 2016.

I follow their guide, it worked for this issue but would face another issue #612

Finally, if your OS is Linux and you use Miniconda or Anaconda to manage your environment, you can run these commands to make it work.

Fix AttributeError: module 'pandas' has no attribute 'tslib'AttributeError: module 'pandas' has no attribute 'tslib' when importing ggplot (#662)

ggplot_path="$CONDA_PREFIX/lib/python3.7/site-packages/ggplot"
sed -i 's/pd.tslib.Timestamp/pd.Timestamp/g' "$ggplot_path/dataUtils.py"
sed -i 's/pd.tslib.Timestamp/pd.Timestamp/g' "$ggplot_path/stats/smoothers.py"
sed -i 's/from pandas.lib import Timestamp/from pandas import Timestamp/g' "$ggplot_path/stats/smoothers.py"

Fix AttributeError: 'DataFrame' object has no attribute 'sort' (#612)

sed -i 's/.sort(/.sort_values(/g' "$ggplot_path/ggplot.py"
sed -i 's/.sort(/.sort_values(/g' "$ggplot_path/stats/stat_smooth.py"
sed -i 's/np.ar.sort_values(/np.sort(/g' "$ggplot_path/stats/stat_smooth.py"

Simple workaround

In case it is not really necessary to use pandas==1.0.4, simply downgrading the pandas version with: pip install pandas==0.19.2 will solve these two problems.

@lcoome
Copy link

lcoome commented Jun 16, 2020

As others have said, the package hasn't been updated since 2016. Use plotnine instead:

# Using pip
$ pip install plotnine         # 1. should be sufficient for most
$ pip install 'plotnine[all]'  # 2. includes extra/optional packages

# Or using conda
$ conda install -c conda-forge plotnine

@singkwan
Copy link

Thanks for suggestions how to fix, but yeah these workarounds don't really work for places where you share server environments as its very messy. Wondering why master hasn't been updated since 2016, anyone know?

@Davis782
Copy link

Davis782 commented Jul 3, 2020

Try the following solution instead of odo.......

https://tereshenkov.wordpress.com/2018/02/08/adding-ipython-sql-magic-to-jupyter-notebook/

@Davis782
Copy link

Davis782 commented Jul 3, 2020

Thanks for suggestions how to fix, but yeah these workarounds don't really work for places where you share server environments as its very messy. Wondering why master hasn't been updated since 2016, anyone know?

https://tereshenkov.wordpress.com/2018/02/08/adding-ipython-sql-magic-to-jupyter-notebook/

@carlosmontoyamoya
Copy link

in the ggplot/utils.py file
change

date_types = (
    pd.tslib.Timestamp,
    pd.DatetimeIndex,
    pd.Period,
    pd.PeriodIndex,
    datetime.datetime,
    datetime.time
)

to

date_types = (
    pd.Timestamp,
    pd.DatetimeIndex,
    pd.Period,
    pd.PeriodIndex,
    datetime.datetime,
    datetime.time
)

Then do the same in the ggplot/stats/smoothers.py file
AND
comment out
from pandas.lib import Timestamp
I haven't tested out the code yet to see if anything doesnt work, but it imported at least

I did worked for me but had to do some chnages

in utils file
change
date_types = (
pd._tslib.Timestamp,
pd.DatetimeIndex,
pd.Period,
pd.PeriodIndex,
datetime.datetime,
datetime.time
)
instead of
date_types = (
pd.tslib.Timestamp,
pd.DatetimeIndex,
pd.Period,
pd.PeriodIndex,
datetime.datetime,
datetime.time
)

int stats/smoothers.py file
comment out ---> from pandas.lib import Timestamp
and
date_types = (
pd.Timestamp,
pd.DatetimeIndex,
pd.Period,
pd.PeriodIndex,
datetime.datetime,
datetime.time
)

instead of
date_types = (
pd.tslib.Timestamp,
pd.DatetimeIndex,
pd.Period,
pd.PeriodIndex,
datetime.datetime,
datetime.time
)

it should work fine

Works perfect. Thanks

@slon1024
Copy link

slon1024 commented Oct 9, 2020

Might it can be helpful for you as well ❤️

just assume that your ggplot was installed here:
GGPLOT_PATH=~/anaconda3/lib/python3.7/site-packages/ggplot #or just change it for yours

and then

sed -i 's/pd.tslib.Timestamp/pd.Timestamp/g' $GGPLOT_PATH/utils.py
sed -i 's/from pandas.lib/#from pandas.lib/g' $GGPLOT_PATH/stats/smoothers.py
sed -i 's/pd.tslib.Timestamp/pd.Timestamp/g' $GGPLOT_PATH/stats/smoothers.py

@RashikRahman
Copy link

Solution :

This solution worked for me,

goto ggplot/utils.py
then change this

date_types = (
pd.tslib.Timestamp,
pd.DatetimeIndex,
pd.Period,
pd.PeriodIndex,
datetime.datetime,
datetime.time
)

to

date_types = (
pd.Timestamp,
pd.DatetimeIndex,
pd.Period,
pd.PeriodIndex,
datetime.datetime,
datetime.time
)

Then goto to ggplot/stats/smoothers.py
then change

this
from pandas.lib import Timestamp

to
from pandasimport Timestamp

and again change this

date_types = (
pd.tslib.Timestamp,
pd.DatetimeIndex,
pd.Period,
pd.PeriodIndex,
datetime.datetime,
datetime.time
)

to

date_types = (
pd.Timestamp,
pd.DatetimeIndex,
pd.Period,
pd.PeriodIndex,
datetime.datetime,
datetime.time
)

in smoothers.py

@bobturneruk
Copy link

Perhaps related #676

@AAAlex-123
Copy link

Solution

Install plotnine

pip install plotnine

@taaaahahaha
Copy link

taaaahahaha commented Jun 22, 2023

import pandas as pd
x = "2023-06-22 10:05:00-04:00"
pd._libs.tslib.Timestamp(x) fixed it for me instead of pd.tslib.Timestamp(x)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests