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

ValueError: to_rgba: Invalid rgba arg #157

Closed
mushketyk opened this issue Jun 6, 2017 · 13 comments
Closed

ValueError: to_rgba: Invalid rgba arg #157

mushketyk opened this issue Jun 6, 2017 · 13 comments
Labels

Comments

@mushketyk
Copy link

I receive the following error when I use alphalens in Quantopian research:

ValueErrorTraceback (most recent call last)
/usr/local/lib/python2.7/dist-packages/IPython/core/formatters.pyc in __call__(self, obj)
    332                 pass
    333             else:
--> 334                 return printer(obj)
    335             # Finally look for special method names
    336             method = get_real_method(obj, self.print_method)

/usr/local/lib/python2.7/dist-packages/IPython/core/pylabtools.pyc in <lambda>(fig)
    238 
    239     if 'png' in formats:
--> 240         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
    241     if 'retina' in formats or 'png2x' in formats:
    242         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))

/usr/local/lib/python2.7/dist-packages/IPython/core/pylabtools.pyc in print_figure(fig, fmt, bbox_inches, **kwargs)
    122 
    123     bytes_io = BytesIO()
--> 124     fig.canvas.print_figure(bytes_io, **kw)
    125     data = bytes_io.getvalue()
    126     if fmt == 'svg':

/usr/local/lib/python2.7/dist-packages/matplotlib/backend_bases.pyc in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
   2178                     orientation=orientation,
   2179                     dryrun=True,
-> 2180                     **kwargs)
   2181                 renderer = self.figure._cachedRenderer
   2182                 bbox_inches = self.figure.get_tightbbox(renderer)

/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_agg.pyc in print_png(self, filename_or_obj, *args, **kwargs)
    525 
    526     def print_png(self, filename_or_obj, *args, **kwargs):
--> 527         FigureCanvasAgg.draw(self)
    528         renderer = self.get_renderer()
    529         original_dpi = renderer.dpi

/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_agg.pyc in draw(self)
    472 
    473         try:
--> 474             self.figure.draw(self.renderer)
    475         finally:
    476             RendererAgg.lock.release()

/usr/local/lib/python2.7/dist-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     59     def draw_wrapper(artist, renderer, *args, **kwargs):
     60         before(artist, renderer)
---> 61         draw(artist, renderer, *args, **kwargs)
     62         after(artist, renderer)
     63 

/usr/local/lib/python2.7/dist-packages/matplotlib/figure.pyc in draw(self, renderer)
   1157         dsu.sort(key=itemgetter(0))
   1158         for zorder, a, func, args in dsu:
-> 1159             func(*args)
   1160 
   1161         renderer.close_group('figure')

/usr/local/lib/python2.7/dist-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     59     def draw_wrapper(artist, renderer, *args, **kwargs):
     60         before(artist, renderer)
---> 61         draw(artist, renderer, *args, **kwargs)
     62         after(artist, renderer)
     63 

/usr/local/lib/python2.7/dist-packages/matplotlib/axes/_base.pyc in draw(self, renderer, inframe)
   2322 
   2323         for zorder, a in dsu:
-> 2324             a.draw(renderer)
   2325 
   2326         renderer.close_group('axes')

/usr/local/lib/python2.7/dist-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     59     def draw_wrapper(artist, renderer, *args, **kwargs):
     60         before(artist, renderer)
---> 61         draw(artist, renderer, *args, **kwargs)
     62         after(artist, renderer)
     63 

/usr/local/lib/python2.7/dist-packages/matplotlib/lines.pyc in draw(self, renderer)
    737                 self._set_gc_clip(gc)
    738 
--> 739                 ln_color_rgba = self._get_rgba_ln_color()
    740                 gc.set_foreground(ln_color_rgba, isRGBA=True)
    741                 gc.set_alpha(ln_color_rgba[3])

/usr/local/lib/python2.7/dist-packages/matplotlib/lines.pyc in _get_rgba_ln_color(self, alt)
   1249 
   1250     def _get_rgba_ln_color(self, alt=False):
-> 1251         return colorConverter.to_rgba(self._color, self._alpha)
   1252 
   1253     # some aliases....

/usr/local/lib/python2.7/dist-packages/matplotlib/colors.pyc in to_rgba(self, arg, alpha)
    374         except (TypeError, ValueError) as exc:
    375             raise ValueError(
--> 376                 'to_rgba: Invalid rgba arg "%s"\n%s' % (str(arg), exc))
    377 
    378     def to_rgba_array(self, c, alpha=None):

ValueError: to_rgba: Invalid rgba arg "[[ 0.          0.40784314  0.21568628  1.        ]]"
length of rgba sequence should be either 3 or 4

<matplotlib.figure.Figure at 0x7f9aff701090>

Here is code that I have in my notebook.

It displays most of the data and some charts and have a stacktrace among other elements:

screen shot 2017-06-06 at 20 53 26

@luca-s
Copy link
Collaborator

luca-s commented Jun 6, 2017

The bug should have already been fixed in this commit

@twiecki would it be possible to know if Alphalens on Quantipian is updated to the latest commit?

@luca-s
Copy link
Collaborator

luca-s commented Jun 9, 2017

@mushketyk Can you replicate the issue outside Quantopian? I believe the issue was fixed, I cannot replicate that.

@luca-s
Copy link
Collaborator

luca-s commented Jul 11, 2017

I am closing this. If you can see the problem outside Quantopian please feel free to reopen the issue.

@luca-s luca-s closed this as completed Jul 11, 2017
@wukan1986
Copy link

I find same bug in plot_quantile_average_cumulative_return,
I use create_event_study_tear_sheet
quantiles = None
bins =1

@luca-s
Copy link
Collaborator

luca-s commented Aug 23, 2017

@wukan1986 Because the bug should have already been fixed in this commit It is important to know if you are facing the issue on Quantopian (old version of Alphalens) or if you are able to replicate the problem outside Quantopian with the most recent version of Alphalens

@wukan1986
Copy link

@luca-s I reinstall alphalens today, the issue still exist.
I check the source, it's modified in plot_cumulative_returns_by_quantile,
NOT in plot_quantile_average_cumulative_return

`Traceback (most recent call last):

File "d:\Users\Kan\Anaconda3_64\lib\site-packages\IPython\core\formatters.py", line 307, in call
return printer(obj)

File "d:\Users\Kan\Anaconda3_64\lib\site-packages\IPython\core\pylabtools.py", line 240, in
png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))

File "d:\Users\Kan\Anaconda3_64\lib\site-packages\IPython\core\pylabtools.py", line 124, in print_figure
fig.canvas.print_figure(bytes_io, **kw)

File "d:\Users\Kan\Anaconda3_64\lib\site-packages\matplotlib\backend_bases.py", line 2200, in print_figure
**kwargs)

File "d:\Users\Kan\Anaconda3_64\lib\site-packages\matplotlib\backends\backend_agg.py", line 545, in print_png
FigureCanvasAgg.draw(self)

File "d:\Users\Kan\Anaconda3_64\lib\site-packages\matplotlib\backends\backend_agg.py", line 464, in draw
self.figure.draw(self.renderer)

File "d:\Users\Kan\Anaconda3_64\lib\site-packages\matplotlib\artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)

File "d:\Users\Kan\Anaconda3_64\lib\site-packages\matplotlib\figure.py", line 1144, in draw
renderer, self, dsu, self.suppressComposite)

File "d:\Users\Kan\Anaconda3_64\lib\site-packages\matplotlib\image.py", line 139, in _draw_list_compositing_images
a.draw(renderer)

File "d:\Users\Kan\Anaconda3_64\lib\site-packages\matplotlib\artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)

File "d:\Users\Kan\Anaconda3_64\lib\site-packages\matplotlib\axes_base.py", line 2426, in draw
mimage._draw_list_compositing_images(renderer, self, dsu)

File "d:\Users\Kan\Anaconda3_64\lib\site-packages\matplotlib\image.py", line 139, in _draw_list_compositing_images
a.draw(renderer)

File "d:\Users\Kan\Anaconda3_64\lib\site-packages\matplotlib\artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)

File "d:\Users\Kan\Anaconda3_64\lib\site-packages\matplotlib\lines.py", line 803, in draw
ln_color_rgba = self._get_rgba_ln_color()

File "d:\Users\Kan\Anaconda3_64\lib\site-packages\matplotlib\lines.py", line 1344, in _get_rgba_ln_color
return mcolors.to_rgba(self._color, self._alpha)

File "d:\Users\Kan\Anaconda3_64\lib\site-packages\matplotlib\colors.py", line 143, in to_rgba
rgba = _to_rgba_no_colorcycle(c, alpha)

File "d:\Users\Kan\Anaconda3_64\lib\site-packages\matplotlib\colors.py", line 194, in _to_rgba_no_colorcycle
raise ValueError("Invalid RGBA argument: {!r}".format(orig_c))

ValueError: Invalid RGBA argument: 0.0`

@luca-s luca-s reopened this Aug 24, 2017
@luca-s
Copy link
Collaborator

luca-s commented Aug 24, 2017

@wukan1986 thanks for double checking and the hint. I will have a look at this issue.

@luca-s luca-s added the bug label Aug 24, 2017
@luca-s
Copy link
Collaborator

luca-s commented Aug 24, 2017

@wukan1986 I cannot replicate the issue. Could you provide me the minimum amount of code that shows the problem? If you can replicate the issue with the example NBs is fine too.

Also, what version of pandas, numpy and matplotlib are you using?

@wukan1986
Copy link

I try run predictive_vs_non-predictive_factor.ipynb
modify one line
pan = web.DataReader(list(ticker_sector.keys()), "yahoo", '2014-12-01')
to
pan = web.DataReader(list(ticker_sector.keys())[:2], "yahoo", '2014-12-01')

It' s can replicate the issue

(d:\Users\Kan\Anaconda3_64) C:\Users\Kan>pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
alphalens (0.1.1)
matplotlib (2.0.2)
numpy (1.13.1)
pandas (0.20.3)
pandas-datareader (0.5.0)

@luca-s
Copy link
Collaborator

luca-s commented Aug 28, 2017

I cannot replicate the issue. Can you show me the output of web.DataReader?

I am using pandas 0.18.2 and I am forced to use google instead of yahoo as the latter doesn't work anymore with old versions of pandas (I didn't try the new ones).

import pandas_datareader.data as web
pan = web.DataReader(list(ticker_sector.keys())[:2], "google", '2014-12-01')
pan['Open']

Output:

ETFC | PNC
-- | --

22.66 | 87.37
22.17 | 86.60
22.60 | 87.50
22.94 | 88.12
23.50 | 88.84
23.72 | 90.11
23.25 | 89.42
23.58 | 90.37
23.64 | 89.04
23.19 | 88.05
22.77 | 88.31
22.35 | 86.83
22.39 | 87.60
23.67 | 90.78
23.94 | 92.64
24.23 | 91.71

@wukan1986
Copy link

google is blocked in china, so i still use yahoo this time.

import pandas_datareader.data as web
pan = web.DataReader(list(ticker_sector.keys())[:2], "yahoo", '2014-12-01')
pan['Open']

the two symbols are A and AA

Date A AA
2017-08-28 63.099998 41.430000
2017-08-25 63.060001 41.680000
2017-08-24 62.869999 40.880001
2017-08-23 62.720001 39.560001
2017-08-22 61.869999 38.740002
2017-08-21 61.090000 38.189999
2017-08-18 60.759998 37.880001
2017-08-17 62.000000 39.000000
2017-08-16 62.150002 37.959999
2017-08-15 59.700001 37.299999
2017-08-14 59.799999 38.110001
2017-08-11 58.700001 37.209999
2017-08-10 59.349998 38.119999
2017-08-09 60.070000 39.209999
2017-08-08 60.669998 38.500000
2017-08-07 60.160000 38.000000
2017-08-04 60.520000 37.340000
2017-08-03 60.150002 37.279999
2017-08-02 60.000000 36.270000
2017-08-01 60.040001 36.459999
2017-07-31 60.320000 35.970001
2017-07-28 59.910000 36.169998
2017-07-27 59.820000 36.840000
2017-07-26 60.580002 37.419998
2017-07-25 61.570000 37.070000
2017-07-24 61.380001 36.590000
2017-07-21 60.830002 36.549999
2017-07-20 61.450001 35.950001
2017-07-19 61.320000 36.610001
2017-07-18 61.430000 36.400002
... ... ...
2015-01-13 40.470001 39.577412
2015-01-12 40.610001 39.409199
2015-01-09 41.000000 38.520088
2015-01-08 40.240002 37.630981
2015-01-07 39.520000 36.717838
2015-01-06 39.810001 36.093060
2015-01-05 40.320000 37.582920
2015-01-02 41.180000 38.135609
2014-12-31 41.389999 38.087551
2014-12-30 41.209999 37.799191
2014-12-29 41.360001 38.063519
2014-12-26 41.340000 38.159641
2014-12-24 41.419998 37.895309
2014-12-23 41.980000 37.967400
2014-12-22 41.380001 38.375912
2014-12-19 40.900002 37.919338
2014-12-18 40.480000 37.198441
2014-12-17 38.340000 35.035740
2014-12-16 38.299999 36.141121
2014-12-15 40.070000 36.189178
2014-12-12 40.200001 36.093060
2014-12-11 40.500000 37.558891
2014-12-10 41.360001 38.399940
2014-12-09 40.990002 38.255760
2014-12-08 42.230000 40.610699
2014-12-05 42.230000 41.716080
2014-12-04 42.150002 41.643990
2014-12-03 41.980000 41.595928
2014-12-02 41.599998 41.139359
2014-12-01 42.689999 41.812199
691 rows × 2 columns

@luca-s
Copy link
Collaborator

luca-s commented Aug 31, 2017

I was able to replicate the issue, thanks @wukan1986

luca-s added a commit to luca-s/alphalens that referenced this issue Aug 31, 2017
luca-s added a commit to luca-s/alphalens that referenced this issue Aug 31, 2017
luca-s added a commit that referenced this issue Sep 1, 2017
@luca-s
Copy link
Collaborator

luca-s commented Sep 1, 2017

This should be fixed now.

@luca-s luca-s closed this as completed Sep 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants