Code Monkey home page Code Monkey logo

Comments (35)

Aycrazy avatar Aycrazy commented on August 17, 2024 56

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.

Munaze avatar Munaze commented on August 17, 2024 12

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.

idantene avatar idantene commented on August 17, 2024 12

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.

from ggpy.

liaojiahui-r avatar liaojiahui-r commented on August 17, 2024 8

Issue still there... Python 3.8

0^0

from ggpy.

lindsayveazey avatar lindsayveazey commented on August 17, 2024 6

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.

userqin avatar userqin commented on August 17, 2024 5

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

from ggpy.

mabu-dev avatar mabu-dev commented on August 17, 2024 4

Is there no fix to this issue?

from ggpy.

SamuelMarks avatar SamuelMarks commented on August 17, 2024 4

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

from ggpy.

hnguyentt avatar hnguyentt commented on August 17, 2024 4

Issue still there... Python 3.8

0^0

The package ggplot has not been updated since 2016.

from ggpy.

lcoome avatar lcoome commented on August 17, 2024 4

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.

ekalosak avatar ekalosak commented on August 17, 2024 2

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

from ggpy.

AbshkPskr avatar AbshkPskr commented on August 17, 2024 1

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

from ggpy.

mabu-dev avatar mabu-dev commented on August 17, 2024 1

Works like magic! Thanks dude. 👍

from ggpy.

hnguyentt avatar hnguyentt commented on August 17, 2024 1

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.

singkwan avatar singkwan commented on August 17, 2024 1

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.

slon1024 avatar slon1024 commented on August 17, 2024 1

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.

taaaahahaha avatar taaaahahaha commented on August 17, 2024 1

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.

mmellor1 avatar mmellor1 commented on August 17, 2024

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.

novostavsky avatar novostavsky commented on August 17, 2024

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.

Aycrazy avatar Aycrazy commented on August 17, 2024

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

from ggpy.

brianmackenna avatar brianmackenna commented on August 17, 2024

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.

Aycrazy avatar Aycrazy commented on August 17, 2024

yes. Thanks. Should have proofread

from ggpy.

xunhuan-li avatar xunhuan-li commented on August 17, 2024

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.

brianmackenna avatar brianmackenna commented on August 17, 2024

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.

paulathomas avatar paulathomas commented on August 17, 2024

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.

paulathomas avatar paulathomas commented on August 17, 2024

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.

danjenson avatar danjenson commented on August 17, 2024

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

from ggpy.

Lucafi avatar Lucafi commented on August 17, 2024

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.

singkwan avatar singkwan commented on August 17, 2024

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

from ggpy.

Davis782 avatar Davis782 commented on August 17, 2024

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

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

from ggpy.

Davis782 avatar Davis782 commented on August 17, 2024

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.

carlosmontoyamoya avatar carlosmontoyamoya commented on August 17, 2024

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

from ggpy.

RashikRahman avatar RashikRahman commented on August 17, 2024

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.

bobturneruk avatar bobturneruk commented on August 17, 2024

Perhaps related #676

from ggpy.

AAAlex-123 avatar AAAlex-123 commented on August 17, 2024

Solution

Install plotnine

pip install plotnine

from ggpy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.