Skip to content

BUG: pd.Timestamp becomes int in .values printout #53459

@aminnj

Description

@aminnj

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd

print(pd.DataFrame([dict(
    a=1,
    b=pd.Timestamp('2023-01-01 12:00:00'),
    c=pd.Timestamp('2023-01-01 12:00:00'),
)]).values.tolist())
# [[1, Timestamp('2023-01-01 12:00:00'), Timestamp('2023-01-01 12:00:00')]]

print(pd.DataFrame([dict(
    b=pd.Timestamp('2023-01-01 12:00:00'),
    c=pd.Timestamp('2023-01-01 12:00:00'),
)]).values.tolist())
# [[1672574400000000000, 1672574400000000000]]

Issue Description

When all columns in a dataframe are pd.Timestamp, accessing values as strings yields integers. However, when a non-pd.Timestamp column exists in the dataframe, the string representation is as expected.

Expected Behavior

Expected behavior observed when a non-pd.Timestamp column is present in the dataframe

import pandas as pd

print(pd.DataFrame([dict(
    b=pd.Timestamp('2023-01-01 12:00:00'),
    c=pd.Timestamp('2023-01-01 12:00:00'),
)]).values.tolist())

# [[Timestamp('2023-01-01 12:00:00'), Timestamp('2023-01-01 12:00:00')]]

Installed Versions

INSTALLED VERSIONS
------------------
commit           : 965ceca9fd796940050d6fc817707bba1c4f9bff
python           : 3.9.6.final.0
python-bits      : 64
OS               : Darwin
OS-release       : 21.6.0
Version          : Darwin Kernel Version 21.6.0: Thu Mar  9 20:08:59 PST 2023; root:xnu-8020.240.18.700.8~1/RELEASE_X86_64
machine          : x86_64
processor        : i386
byteorder        : little
LC_ALL           : None
LANG             : en_US.UTF-8
LOCALE           : en_US.UTF-8

pandas           : 2.0.2
numpy            : 1.24.3
pytz             : 2023.3
dateutil         : 2.8.2
setuptools       : 58.0.4
pip              : 23.1.2
Cython           : None
pytest           : None
hypothesis       : None
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : None
html5lib         : None
pymysql          : None
psycopg2         : None
jinja2           : 3.1.2
IPython          : None
pandas_datareader: None
bs4              : None
bottleneck       : None
brotli           : None
fastparquet      : None
fsspec           : None
gcsfs            : None
matplotlib       : None
numba            : None
numexpr          : None
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : 10.0.1
pyreadstat       : None
pyxlsb           : None
s3fs             : None
scipy            : None
snappy           : None
sqlalchemy       : 1.4.47
tables           : None
tabulate         : None
xarray           : None
xlrd             : None
zstandard        : None
tzdata           : 2023.3
qtpy             : None
pyqt5            : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugClosing CandidateMay be closeable, needs more eyeballsDatetimeDatetime data dtype

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions