- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 19.2k
 
Description
- 
[x ] I have checked that this issue has not already been reported.
 - 
[x ] I have confirmed this bug exists on the latest version of pandas.
 - 
(optional) I have confirmed this bug exists on the master branch of pandas.
 
Code Sample, a copy-pastable example
import pandas as pd
ts = 1618556707013635762
pdf = pd.DataFrame([{"id": 2, "ts": ts}, {"id": 2, "ts": ts+1}])
pdf["ts"] = pd.array(pdf["ts"], dtype="Int64")
pdf.groupby("id").agg({"ts": "min"})Problem description
The above code will output 1618556707013635840 as the minimum which is incorrect.
Expected Output
Minimum should be 1618556707013635762. I suspect there is a cast happening somewhere during the aggregation.  If we keep the ts column at int64 (i.e. use the non-nullable type) the result is as expected.
Output of pd.show_versions()
INSTALLED VERSIONS
commit           : 2cb9652
python           : 3.9.5.final.0
python-bits      : 64
OS               : Linux
OS-release       : 5.11.7-200.fc33.x86_64
Version          : #1 SMP Wed Mar 17 18:55:20 UTC 2021
machine          : x86_64
processor        : x86_64
byteorder        : little
LC_ALL           :
LANG             : en_US.UTF-8
LOCALE           : en_US.UTF-8
pandas           : 1.2.4
numpy            : 1.20.3
pytz             : 2021.1
dateutil         : 2.8.1
pip              : 21.1.1
setuptools       : 56.0.0
Cython           : None
pytest           : None
hypothesis       : None
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : None
html5lib         : None
pymysql          : None
psycopg2         : None
jinja2           : None
IPython          : 7.24.0
pandas_datareader: None
bs4              : None
bottleneck       : None
fsspec           : None
fastparquet      : None
gcsfs            : None
matplotlib       : None
numexpr          : None
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : None
pyxlsb           : None
s3fs             : None
scipy            : None
sqlalchemy       : None
tables           : None
tabulate         : None
xarray           : None
xlrd             : None
xlwt             : None
numba            : None
Potentially related issues
The issues below seem related, but from what I can see are slightly different:
- ENH: improve the resulting dtype for groupby operations on nullable dtypes #37494 seems like a more general problem where it is a priori unclear what the resulting 
dtypeof the output column should be. For theminandmaxI would expect to get the samedtypeas in the input column. - BUG: groupby mean/median/var should always be float values #41137 For the present issue we actually want to keep the original precision and not cast to float.