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

ggplot doesn't work with latest pandas dataframe #612

Open
zjffdu opened this issue Jul 11, 2017 · 24 comments
Open

ggplot doesn't work with latest pandas dataframe #612

zjffdu opened this issue Jul 11, 2017 · 24 comments

Comments

@zjffdu
Copy link

zjffdu commented Jul 11, 2017

Here's the error I get. This is due to dataframe api change.

'DataFrame' object has no attribute 'sort'
@chethanjjj
Copy link

same issue over here

@chethanjjj
Copy link

@zjffdu temporary fix would to be downgrade your Pandas package to 0.19.2
conda install pandas=0.19.2

@asbhat
Copy link

asbhat commented Jul 18, 2017

This is actually already fixed in the code (9d00182). If you

$ pip uninstall ggplot
$ pip install git+git://github.com/yhat/ggpy.git@9d00182343eccca6486beabd256e8c89fb0c59e8 --no-cache

it should work.

@zjffdu
Copy link
Author

zjffdu commented Jul 19, 2017

@asbhat When would be the next release to include this fix ?

@chethanjjj
Copy link

chethanjjj commented Jul 19, 2017

@asbhat, I still get the same error when installing that specific ggplot version

AttributeError: 'DataFrame' object has no attribute 'sort'

@asbhat
Copy link

asbhat commented Jul 19, 2017

@zjffdu I'm not sure sorry. I just ran into this problem myself last week and figured I would try and help if you were having the same issue

@asbhat
Copy link

asbhat commented Jul 19, 2017

@chethanjjj you're getting that error during the install process? That didn't happen to me. Can you give me more details about how you're installing? Maybe I can help if I can replicate the error

@chethanjjj
Copy link

chethanjjj commented Jul 19, 2017 via email

@pwrosa
Copy link

pwrosa commented Jul 24, 2017

I am seeing the same issue - I think it is because L602 in ggplot still uses sort:

fill_levels = self.data[[fillcol_raw, fillcol]].sort(fillcol_raw)[fillcol].unique()

@asbhat
Copy link

asbhat commented Jul 24, 2017

Thanks @pwrosa that makes sense. I could reproduce the error by running:

ggplot(diamonds, aes(x='clarity', fill='cut')) + geom_bar()

I've opened a PR to fix the issue

@MarcoNiemann
Copy link

It is October already and pandas advanced to version 0.20.3. This problem should be fixed as it renders ggplot unusable for a lot of use-cases.

@roughmar
Copy link

roughmar commented Nov 7, 2017

Any news regarding this issue?

@jmcarpenter2
Copy link

On line 602 of ggplot/ggplot.py, I changed the line from

fill_levels = self.data[[fillcol_raw, fillcol]].sort(fillcol_raw)[fillcol].unique()

to

fill_levels = self.data[[fillcol_raw, fillcol]].sort_values(by=fillcol_raw)[fillcol].unique()

and it worked for my use case. Hope that helps..

@bdoohan
Copy link

bdoohan commented Jan 13, 2018

Has this issue been fixed in the code? Seems only one line needs to be fixed.

@asbhat
Copy link

asbhat commented Jan 14, 2018

There hasn't been an update to master since Nov 2016. At this point I think it's safe to say this package isn't supported anymore 😕

@alzayats
Copy link

Sort is obsolete in pandas package, must use sort_values:

return df[cols].sort(columns='order') -> return df[cols].sort_values(by='order')
df.sort(inplace=True) -> df.sort_values(inplace=True)

Geosyntec/pygridtools#58

@chethanjjj
Copy link

If anyone is still dependent on this package, I would suggest moving over to Seaborn :)

@thinkjrs
Copy link

thinkjrs commented Apr 5, 2018

@chethanjjj Though it's an awesome plotting library, for me it's the Grammar in R's ggplot2 that matters, so Seaborn won't suffice. If you're in my camp, try Plotnine, which I found from this tutorial from @pteehan.

@mstampella
Copy link

OMG!! Starting with Seaborn, really sad about this thread...

@greebie
Copy link

greebie commented Sep 21, 2018

If people are interested in playing whack-a-mole through the python, in addition to [jmcarpenter2 's] (#612 (comment)) comment, there is another instance of sort in ggplot/stats/stat_smooth.py

Change

smoothed_data = smoothed_data.sort('x')

to

smoothed_data = smoothed_data.sort_values('x')

@engie-elkhait-meine
Copy link

I have the same problem. It's so sad to not have updates for this package !

@SaumyaShikhar
Copy link

SAD THREAD

@ZacharyRSmith
Copy link

In case it helps anyone, I received a similar error when trying to import ggplot:

Traceback (most recent call last):
  File "scratch.py", line 3, in <module>
    from ggplot import *
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/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 "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ggplot/geoms/__init__.py", line 1, in <module>
    from .geom_abline import geom_abline
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ggplot/geoms/geom_abline.py", line 1, in <module>
    from .geom import geom
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ggplot/geoms/geom.py", line 3, in <module>
    from ..ggplot import ggplot
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ggplot/ggplot.py", line 13, in <module>
    from .aes import aes
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ggplot/aes.py", line 11, in <module>
    from . import utils
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ggplot/utils.py", line 81, in <module>
    pd.tslib.Timestamp,
AttributeError: 'module' object has no attribute 'tslib'

Here are my pkg vers:

➜  sandbox-py pip show ggplot
Name: ggplot
Version: 0.11.5
Summary: ggplot for python
Home-page: https://github.com/yhat/ggplot/
Author: Greg Lamp
Author-email: greg@yhathq.com
License: BSD
Location: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Requires: six, statsmodels, brewer2mpl, matplotlib, scipy, patsy, pandas, cycler, numpy
Required-by: 
You are using pip version 10.0.1, however version 19.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
➜  sandbox-py pip show pandas
Name: pandas
Version: 0.24.1
Summary: Powerful data structures for data analysis, time series, and statistics
Home-page: http://pandas.pydata.org
Author: None
Author-email: None
License: BSD
Location: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Requires: python-dateutil, pytz, numpy
Required-by: statsmodels, plotnine, mizani, ggplot, geopandas
You are using pip version 10.0.1, however version 19.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

I first tried this, but it did not resolve my error:

$ pip uninstall ggplot
$ pip install git+git://github.com/yhat/ggpy.git@9d00182343eccca6486beabd256e8c89fb0c59e8 --no-cache

Because "There hasn't been an update to master since Nov 2016. At this point I think it's safe to say this package isn't supported anymore" - @asbhat , I switched over to plotnine, which (as far as I can tell) has the same API as ggplot. Life is good again.

@vijetadeshpande
Copy link

I had same issue and fixed it as below:

    # check if input is dataframe
    if isinstance(smoothed_data, pd.DataFrame):
        smoothed_data = smoothed_data.sort_values('x')
    else:
        smoothed_data = smoothed_data.sort('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