Numpy isfinite typeerror
<p>I know I'm doing it wrong but I don't see how to do it right. In my executing code, the series I have comes from a large dataframe that I've done a groupby on. In the real code, the assignment happens in a loop as select various slices from the series.</p>

<p>The code below results in TypeError: ufunc 'isfinite' not supported for the input type. I'm positive that this is due to a reference, not a copy or something on that line, but I'm just not good enough in Python to understand how to fix it.</p>

<pre><code>import sys
import numpy as np
import pandas as pd
import random
import matplotlib.pyplot as plt

plt.ion()
period = 36
ward_dates = pd.date_range(start=pd.datetime.today(), freq='M', periods=period)
list_size = 6
ward_counts = [[] for i in range(list_size)]
for idx in range(list_size):
    current_list = [np.random.randint(0, 500000) for r in range(period)]
    ward_counts[idx] = current_list
plt.stackplot(ward_dates, ward_counts)
plt.close('all')

units = np.random.choice(['U1', 'U2', 'U3'], size=period)
index = pd.MultiIndex.from_arrays([units, ward_dates])
s1 = pd.Series([np.random.randint(0, 5000) for r in range(period)], index=index)

ward_counts = [[] for i in range(3)]
l1 = [int(x) for x in s1.loc['U1'].values]
ward_counts[0] = l1
l1 = [int(x) for x in s1.loc['U2'].values]
ward_counts[1] = l1
l1 = [int(x) for x in s1.loc['U3'].values]
ward_counts[2] = l1
plt.stackplot(ward_dates, ward_counts)
</code></pre>

<p>The first stackplot works just fine. The second fails. I know therefore the issue is in grabbing the values. The resulting lists both LOOK identical (ints with the same number of values) but the second fails.</p>

<p>I've looked at slicing, deepcopy, etc. but they continue to fail, so the fundamental problem is my lack of understanding. I'm also sure this is a duplicate of many others but i just don't grasp the issue. </p>

<p><strong>Update</strong></p>

<p>Here is the trackback</p>

<blockquote>
  <p>File
  "C:/Users/dgrawroc/PycharmProjects/fs_admin_reports/fs_admin_reports/oldstuff.py",
  line 47, in main
      plt.stackplot(ward_dates, ward_counts)   File "C:\Users\dgrawroc\Documents\Anaconda3\envs\m2\lib\site-packages\matplotlib\pyplot.py",
  line 3326, in stackplot
      ret = ax.stackplot(x, *args, **kwargs)   File "C:\Users\dgrawroc\Documents\Anaconda3\envs\m2\lib\site-packages\matplotlib__init__.py",
  line 1811, in inner
      return func(ax, *args, **kwargs)   File "C:\Users\dgrawroc\Documents\Anaconda3\envs\m2\lib\site-packages\matplotlib\axes_axes.py",
  line 4443, in stackplot
      return mstack.stackplot(self, x, *args, **kwargs)   File "C:\Users\dgrawroc\Documents\Anaconda3\envs\m2\lib\site-packages\matplotlib\stackplot.py",
  line 113, in stackplot
      **kwargs))   File "C:\Users\dgrawroc\Documents\Anaconda3\envs\m2\lib\site-packages\matplotlib__init__.py",
  line 1811, in inner
      return func(ax, *args, **kwargs)   File "C:\Users\dgrawroc\Documents\Anaconda3\envs\m2\lib\site-packages\matplotlib\axes_axes.py",
  line 4608, in fill_between
      y2 = ma.masked_invalid(self.convert_yunits(y2))   File "C:\Users\dgrawroc\Documents\Anaconda3\envs\m2\lib\site-packages\numpy\ma\core.py",
  line 2293, in masked_invalid
      condition = ~(np.isfinite(a)) TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely
  coerced to any supported types according to the casting rule ''safe''</p>
</blockquote>