title: How does pandas.grouped.apply( ) decide on output, and why does this depend on whether some groups return None?
body: <p>I'm a little mistified by the behaviour of grouped.apply(). The type of res1 and res2 are different. res1 is Series and res2 is DataFrame. Can someone explain the rationale?   </p>
  
  <pre><code>    import pandas as pd
      import numpy as np
  
      def exampleFrame():
          animal = ['Tiger','Lamb','Pony']
          sizeCat   = ['Tiny','Small','Medium','Large','Huge']
          nPeriods  = 150
          D         = pd.date_range('1/1/2000', periods=nPeriods)
          T         = np.random.choice( animal , nPeriods )
          S         = np.random.choice( sizeCat, nPeriods )
          P         = np.cumsum( np.random.randn(nPeriods) )
          df        = pd.DataFrame( {'Price':P,'Animal':T,'Size':S,'Days':D} )
          df.set_index( ['Days'], inplace = True)
          return df
  
      def sometimesNone(grp):
          if np.random.choice( [True, False] ):
              return grp.iloc[0]
          else:
              return None
  
      def neverNone(grp):
          return grp.iloc[0]                                
  
      df   = exampleFrame()
      res1 = df.groupby(['Animal']).apply( sometimesNone )
      res2 = df.groupby(['Animal']).apply( neverNone )
      print res1.__class__
      print res2.__class__
  </code></pre>