<p dir="auto">I tried to produce a stand-alone example but couldn't so far. Maybe the answer is already apparent though. This started happening just recently (maybe after updated pandas to 0.17.1) but worked well before. I'm doing a multi-column <code class="notranslate">agg</code> in a groupby. One of the columns is a datetime of which I want the first element:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="(Pdb) t.groupby(['block_dir']).first()
                                 dt    sid  amount     price symbol  \
block_dir                                                             
1         2003-01-02 15:56:00+00:00  21719     -62  0.963811   AIRN   "><pre class="notranslate"><code class="notranslate">(Pdb) t.groupby(['block_dir']).first()
                                 dt    sid  amount     price symbol  \
block_dir                                                             
1         2003-01-02 15:56:00+00:00  21719     -62  0.963811   AIRN   
</code></pre></div>
<p dir="auto">Works fine, however:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="          order_sign  block_time  
block_dir                         
1              False           0  
(Pdb) t.groupby(['block_dir']).agg({'dt': 'first'})
                            dt
block_dir                     
1          1041522960000000000"><pre class="notranslate"><code class="notranslate">          order_sign  block_time  
block_dir                         
1              False           0  
(Pdb) t.groupby(['block_dir']).agg({'dt': 'first'})
                            dt
block_dir                     
1          1041522960000000000
</code></pre></div>
<h4 dir="auto">Expected Output</h4>
<h4 dir="auto">output of <code class="notranslate">pd.show_versions()</code></h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="INSTALLED VERSIONS
------------------
commit: None
python: 2.7.11.final.0
python-bits: 64
OS: Linux
OS-release: 3.13.0-77-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8

pandas: 0.17.1
nose: 1.3.7
pip: 8.0.2
setuptools: 19.6.2
Cython: 0.23.4
numpy: 1.10.4
scipy: 0.16.1
statsmodels: 0.6.1
IPython: 3.2.1
sphinx: 1.3.1
patsy: 0.4.0
dateutil: 2.4.2
pytz: 2015.4
blosc: None
bottleneck: 1.0.0
tables: 3.2.2
numexpr: 2.4.3
matplotlib: 1.4.3
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.3.2
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.8
pymysql: None
psycopg2: 2.6.1 (dt dec pq3 ext)
Jinja2: None"><pre class="notranslate"><code class="notranslate">INSTALLED VERSIONS
------------------
commit: None
python: 2.7.11.final.0
python-bits: 64
OS: Linux
OS-release: 3.13.0-77-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8

pandas: 0.17.1
nose: 1.3.7
pip: 8.0.2
setuptools: 19.6.2
Cython: 0.23.4
numpy: 1.10.4
scipy: 0.16.1
statsmodels: 0.6.1
IPython: 3.2.1
sphinx: 1.3.1
patsy: 0.4.0
dateutil: 2.4.2
pytz: 2015.4
blosc: None
bottleneck: 1.0.0
tables: 3.2.2
numexpr: 2.4.3
matplotlib: 1.4.3
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.3.2
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.8
pymysql: None
psycopg2: 2.6.1 (dt dec pq3 ext)
Jinja2: None
</code></pre></div>
<p dir="auto">Hi all,</p>
<p dir="auto">I've found an inconsistency between pandas 0.17 and 0.16.2 when aggregating on UTC timestamps. Here is a snippet to reproduce the problem:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np
import pandas as pd

np.random.seed(42)

data = pd.DataFrame({
    'factor': np.random.randint(0, 3, size=60),
    'time': pd.date_range('01/01/2000 00:00', periods=60, freq='s', tz='UTC')
})

gp = data.groupby('factor')

print(gp['time'].min())
print(gp['time'].max())"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-k">import</span> <span class="pl-s1">pandas</span> <span class="pl-k">as</span> <span class="pl-s1">pd</span>

<span class="pl-s1">np</span>.<span class="pl-s1">random</span>.<span class="pl-en">seed</span>(<span class="pl-c1">42</span>)

<span class="pl-s1">data</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>({
    <span class="pl-s">'factor'</span>: <span class="pl-s1">np</span>.<span class="pl-s1">random</span>.<span class="pl-en">randint</span>(<span class="pl-c1">0</span>, <span class="pl-c1">3</span>, <span class="pl-s1">size</span><span class="pl-c1">=</span><span class="pl-c1">60</span>),
    <span class="pl-s">'time'</span>: <span class="pl-s1">pd</span>.<span class="pl-en">date_range</span>(<span class="pl-s">'01/01/2000 00:00'</span>, <span class="pl-s1">periods</span><span class="pl-c1">=</span><span class="pl-c1">60</span>, <span class="pl-s1">freq</span><span class="pl-c1">=</span><span class="pl-s">'s'</span>, <span class="pl-s1">tz</span><span class="pl-c1">=</span><span class="pl-s">'UTC'</span>)
})

<span class="pl-s1">gp</span> <span class="pl-c1">=</span> <span class="pl-s1">data</span>.<span class="pl-en">groupby</span>(<span class="pl-s">'factor'</span>)

<span class="pl-en">print</span>(<span class="pl-s1">gp</span>[<span class="pl-s">'time'</span>].<span class="pl-en">min</span>())
<span class="pl-en">print</span>(<span class="pl-s1">gp</span>[<span class="pl-s">'time'</span>].<span class="pl-en">max</span>())</pre></div>
<p dir="auto">On 0.16.2 the output seems correct, i.e it returns timestamps:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [1]: %run bug_pandas.py
factor
0    2000-01-01 00:00:01+00:00
1    2000-01-01 00:00:07+00:00
2    2000-01-01 00:00:00+00:00
Name: time, dtype: object
factor
0    2000-01-01 00:00:57+00:00
1    2000-01-01 00:00:54+00:00
2    2000-01-01 00:00:59+00:00
Name: time, dtype: object"><pre class="notranslate"><code class="notranslate">In [1]: %run bug_pandas.py
factor
0    2000-01-01 00:00:01+00:00
1    2000-01-01 00:00:07+00:00
2    2000-01-01 00:00:00+00:00
Name: time, dtype: object
factor
0    2000-01-01 00:00:57+00:00
1    2000-01-01 00:00:54+00:00
2    2000-01-01 00:00:59+00:00
Name: time, dtype: object
</code></pre></div>
<p dir="auto">However on 0.17 it returns timestamps as integers:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [1]: %run bug_pandas.py
factor
0    946684801000000000
1    946684807000000000
2    946684800000000000
Name: time, dtype: int64
factor
0    946684857000000000
1    946684854000000000
2    946684859000000000
Name: time, dtype: int64"><pre class="notranslate"><code class="notranslate">In [1]: %run bug_pandas.py
factor
0    946684801000000000
1    946684807000000000
2    946684800000000000
Name: time, dtype: int64
factor
0    946684857000000000
1    946684854000000000
2    946684859000000000
Name: time, dtype: int64
</code></pre></div>
<p dir="auto">It should be noted that the problem doesn't appear with <code class="notranslate">tz=None</code>.</p>
<p dir="auto">Thanks for your help,</p>
<p dir="auto">Alexandre</p>