Comments (35)
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
from ggpy.
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
from ggpy.
in the ggplot/utils.py file
changedate_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 leastI 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:
- Change
pandas.tslib.Timestamp
topandas.Timestamp
- Change
from pandas.lib import Timestamp
tofrom pandas import Timestamp
.
from ggpy.
Issue still there... Python 3.8
0^0
from ggpy.
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.
from ggpy.
AttributeError: module 'pandas' has no attribute 'tslib'
I got the same error on myu imac book. How to solve this issue ?
from ggpy.
Is there no fix to this issue?
from ggpy.
Just sent through a PR to fix this problem: #664
from ggpy.
Issue still there... Python 3.8
0^0
The package ggplot has not been updated since 2016.
from ggpy.
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
from ggpy.
Can we merge this: #664 ? Seems like the simple import fix is the consensus solution?
from ggpy.
for temporary fix downgrade pandas to 0.19.2
!pip install pandas==0.19.2
from ggpy.
Works like magic! Thanks dude. 👍
from ggpy.
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.
from ggpy.
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?
from ggpy.
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
from ggpy.
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)
from ggpy.
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'
from ggpy.
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'
from ggpy.
I assume we can change
pd.tslib.Timestamp to pd.Timestamp in the source file
from ggpy.
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
)
from ggpy.
yes. Thanks. Should have proofread
from ggpy.
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
from ggpy.
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
from ggpy.
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.
from ggpy.
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.
from ggpy.
Fresh python 3.7.6 install and this fails. Second merging #664
from ggpy.
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!
from ggpy.
Any fix for this? Still an issue with pandas==1.0.4 and python 3.7
from ggpy.
Try the following solution instead of odo.......
https://tereshenkov.wordpress.com/2018/02/08/adding-ipython-sql-magic-to-jupyter-notebook/
from ggpy.
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/
from ggpy.
in the ggplot/utils.py file
changedate_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 leastI 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
from ggpy.
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
from ggpy.
Perhaps related #676
from ggpy.
Solution
Install plotnine
pip install plotnine
from ggpy.
Related Issues (20)
- [Feature Request]: Plot directly onto a matplotlib axis HOT 1
- the numbers squeeze on the x-axis or y-axis
- Wrong code
- Is this project dead? HOT 16
- "metaclass conflict" error when using ggplot 0.6.8 with six 1.10.0+
- Import does not work with pandas 0.23.4
- unable to import in jupyter notebook HOT 5
- Warning received when using color aesthetic with geom_point
- Import issue in jupyter notebook
- Can't facet on variable with more than 9 levels
- facet_grid fail with a category type
- facet_grid repeat x-axis
- pandas sort issue
- How about make it available with dfply?
- Link to an actively developed project called "plotnine" which provides ggplot functionality in python.
- ggplot installs for python3.9.1.0, but import ggplot gets error re pandas attribute tslib HOT 2
- plot multiple geoms on top of each other
- Looking for `ggplot` substitution HOT 2
- Questions about Copilot + Open Source Software Hierarchy
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ggpy.