Code Monkey home page Code Monkey logo

Comments (9)

glamp avatar glamp commented on July 18, 2024

I'm getting this sporadically as well. I'll take a look but it looks like ggplot is passing an invalid data type to statsmodels. Does it work with method="lm" for stat_smooth?

On Oct 15, 2013, at 10:05 AM, Bart [email protected] wrote:

For every example I try (be it in IPython or not) I get the following error:

File "ggplot_test.py", line 11, in
ggsave(p, "test.png")
File "C:\Python27\lib\site-packages\ggplot\utils\utils.py", line 4, in ggsave
print (plot)
File "C:\Python27\lib\site-packages\ggplot\ggplot.py", line 209, in repr
callbacks = geom.plot_layer(layer)
File "C:\Python27\lib\site-packages\ggplot\geoms\stat_smooth.py", line 37, in plot_layer
y, y1, y2 = smoothers.lowess(x, y)
File "C:\Python27\lib\site-packages\ggplot\components\smoothers.py", line 38, in lowess
result = smlowess(np.array(y), np.array(x), frac=span)
File "C:\Python27\lib\site-packages\statsmodels\nonparametric\smoothers_lowess.py", line 128, in lowess
exog = np.asarray(exog, float)
File "C:\Python27\lib\site-packages\numpy-1.7.0-py2.7-win32.egg\numpy\core\numeric.py", line 320, in asarray
return array(a, dtype, copy=False, order=order)
TypeError: float() argument must be a string or a number
The specific example:

from ggplot import *

p = ggplot(aes(x='date', y='beef'), data=meat) +
geom_point(color='lightblue') +
geom_line(alpha=0.25) +
stat_smooth(span=.05, color='black') +
ggtitle("Beef: It's What's for Dinner") +
xlab("Date") +
ylab("Head of Cattle Slaughtered")

ggsave(p, "test.png")


Reply to this email directly or view it on GitHub.

from ggpy.

bart6114 avatar bart6114 commented on July 18, 2024

I get a different error when using method="lm"

 File "ryp_ggplot.py", line 11, in <module>
   ggsave(p, "test.png")
 File "C:\Python27\lib\site-packages\ggplot\utils\utils.py", line 4, in ggsave
   print (plot)
 File "C:\Python27\lib\site-packages\ggplot\ggplot.py", line 209, in __repr__
   callbacks = geom.plot_layer(layer)
 File "C:\Python27\lib\site-packages\ggplot\geoms\stat_smooth.py", line 33, in plot_layer
   y, y1, y2 = smoothers.lm(x, y)
 File "C:\Python27\lib\site-packages\ggplot\components\smoothers.py", line 24, in lm
   fit = sm.OLS(df.y,df[['x','const']]).fit()
 File "C:\Python27\lib\site-packages\statsmodels\regression\linear_model.py", line 479, in __init__
   hasconst=hasconst)
 File "C:\Python27\lib\site-packages\statsmodels\regression\linear_model.py", line 381, in __init__
   weights=weights, hasconst=hasconst)
 File "C:\Python27\lib\site-packages\statsmodels\regression\linear_model.py", line 79, in __init__
   super(RegressionModel, self).__init__(endog, exog, **kwargs)
 File "C:\Python27\lib\site-packages\statsmodels\base\model.py", line 137, in __init__
   self.initialize()
 File "C:\Python27\lib\site-packages\statsmodels\regression\linear_model.py", line 88, in initialize
   self.rank = rank(self.exog)
 File "C:\Python27\lib\site-packages\statsmodels\tools\tools.py", line 381, in rank
   D = svdvals(X)
 File "C:\Python27\lib\site-packages\scipy\linalg\decomp_svd.py", line 146, in svdvals
   check_finite=check_finite)
 File "C:\Python27\lib\site-packages\scipy\linalg\decomp_svd.py", line 100, in svd
   full_matrices=full_matrices, overwrite_a=overwrite_a)
TypeError: float() argument must be a string or a number

I does however work when omitting stat_smooth()

from ggpy.

glamp avatar glamp commented on July 18, 2024

Ok thanks for debugging. Should be able to patch this fairly easily.

In other news, the scipy stack trace sure is nasty!

On Oct 15, 2013, at 10:34 AM, Bart [email protected] wrote:

I get a different error when using method="lm"

File "ryp_ggplot.py", line 11, in
ggsave(p, "test.png")
File "C:\Python27\lib\site-packages\ggplot\utils\utils.py", line 4, in ggsave
print (plot)
File "C:\Python27\lib\site-packages\ggplot\ggplot.py", line 209, in repr
callbacks = geom.plot_layer(layer)
File "C:\Python27\lib\site-packages\ggplot\geoms\stat_smooth.py", line 33, in plot_layer
y, y1, y2 = smoothers.lm(x, y)
File "C:\Python27\lib\site-packages\ggplot\components\smoothers.py", line 24, in lm
fit = sm.OLS(df.y,df[['x','const']]).fit()
File "C:\Python27\lib\site-packages\statsmodels\regression\linear_model.py", line 479, in init
hasconst=hasconst)
File "C:\Python27\lib\site-packages\statsmodels\regression\linear_model.py", line 381, in init
weights=weights, hasconst=hasconst)
File "C:\Python27\lib\site-packages\statsmodels\regression\linear_model.py", line 79, in init
super(RegressionModel, self).init(endog, exog, **kwargs)
File "C:\Python27\lib\site-packages\statsmodels\base\model.py", line 137, in init
self.initialize()
File "C:\Python27\lib\site-packages\statsmodels\regression\linear_model.py", line 88, in initialize
self.rank = rank(self.exog)
File "C:\Python27\lib\site-packages\statsmodels\tools\tools.py", line 381, in rank
D = svdvals(X)
File "C:\Python27\lib\site-packages\scipy\linalg\decomp_svd.py", line 146, in svdvals
check_finite=check_finite)
File "C:\Python27\lib\site-packages\scipy\linalg\decomp_svd.py", line 100, in svd
full_matrices=full_matrices, overwrite_a=overwrite_a)
TypeError: float() argument must be a string or a number
I does however work when omitting stat_smooth()


Reply to this email directly or view it on GitHub.

from ggpy.

desilinguist avatar desilinguist commented on July 18, 2024

I was getting this error if I had a really old version of pandas installed.

from ggpy.

stefaneng avatar stefaneng commented on July 18, 2024

I had the same results as @desilinguist. If you pip install pandas it should remove these errors.

from ggpy.

glamp avatar glamp commented on July 18, 2024

Thanks! This worked for me too.

$ pip install -U pandas

On Tue, Oct 15, 2013 at 2:55 PM, Stefan Eng [email protected]:

I had the same results as @desilinguist https://github.com/desilinguist.
If you pip install pandas it should remove these errors.


Reply to this email directly or view it on GitHubhttps://github.com//issues/27#issuecomment-26362095
.

from ggpy.

bart6114 avatar bart6114 commented on July 18, 2024

Hmz, unfortunately I still can't get the stat_smooth function working. I updated pandas to v. 0.12.0 and made sure the other required packages are also up-to-date. I however keep getting this error:

Traceback (most recent call last):
  File "ggplot.py", line 9, in <module>
    ylab("Head of Cattle Slaughtered")
  File "C:\Python27\lib\site-packages\ggplot\ggplot.py", line 209, in __repr__
    callbacks = geom.plot_layer(layer)
  File "C:\Python27\lib\site-packages\ggplot\geoms\stat_smooth.py", line 37, in plot_layer
    y, y1, y2 = smoothers.lowess(x, y)
  File "C:\Python27\lib\site-packages\ggplot\components\smoothers.py", line 38, in lowess
    result = smlowess(np.array(y), np.array(x), frac=span)
  File "C:\Python27\lib\site-packages\statsmodels\nonparametric\smoothers_lowess.py", line 128, in lowess
    exog = np.asarray(exog, float)
  File "C:\Python27\lib\site-packages\numpy\core\numeric.py", line 460, in asarray
    return array(a, dtype, copy=False, order=order)
TypeError: float() argument must be a string or a number

When using this example:

from ggplot import *

print ggplot(aes(x='date', y='beef'), data=meat) + \
    geom_point(color='lightblue') + \
    geom_line(alpha=0.25) + \
    stat_smooth(span=.05, color='black') + \
    ggtitle("Beef: It's What's for Dinner") + \
    xlab("Date") + \
    ylab("Head of Cattle Slaughtered")

plt.show(1)

from ggpy.

dan-blanchard avatar dan-blanchard commented on July 18, 2024

@bart6114 are you sure pandas actually got upgraded? Pip is pretty notorious for not following through with upgrades if you have an older version of the package in some /tmp/pip* build directory. I'd double-check by importing pandas and checking the output of pandas.__version__.

from ggpy.

bart6114 avatar bart6114 commented on July 18, 2024

Thanks @dan-blanchard , that was the problem!

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.