title: max not working on series/list inside of for loop
body: <p>I have the following function written to find the most recent date in my dataset prior to the year I am calculating for. I am having trouble understanding why it will not work in a for loop, but it will outside of one. If I write it with a hardcoded value as the year, it will run just fine. However, when I try to put it in a loop, it will give the following error:</p>
  
  <blockquote>
    <p>'ValueError: max() arg is an empty sequence'</p>
  </blockquote>
  
  <p>Thank you for any insight on why this is error is thrown, and what I can do to fix it.</p>
  
  <pre><code>def max_date_prior_to_year(dates, yr):
       return max(dates[dates&lt;pd.to_datetime(str(yr)+'-01-01')])
  
  print(max_date_prior_to_year(df['Date'], 2014))
  2013-10-15 00:00:00
  
  for yr in [2011,2012,2013,2014]:
      print(max_date_prior_to_year(df['Date'], yr))
  ValueError: max() arg is an empty sequence
  </code></pre>