Skip to content

BUG: ExtensionArray with 2D datetime64 values errors on display formatting #38390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
3 tasks done
BryanCutler opened this issue Dec 9, 2020 · 3 comments
Open
3 tasks done
Labels
Bug Datetime Datetime data dtype ExtensionArray Extending pandas with custom dtypes or arrays. Output-Formatting __repr__ of pandas objects, to_string

Comments

@BryanCutler
Copy link
Contributor

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

  • 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.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

import numpy as np
import pandas as pd
import pandas.io.formats.format as fmt
x = pd.date_range('2018-01-01', periods=5, freq='H').to_numpy()
x = np.tile(x, (3, 1))
formatter = fmt.Datetime64Formatter(x)
result = formatter.get_result()

Problem description

When using a Pandas ExtensionArray that has 2D values of Datetime64 dtype, Pandas errors on formatting the values with the following:

File "/ib/python3.8/site-packages/pandas/io/formats/printing.py", line 73, in <listcomp>
    return [x.rjust(max_len) for x in texts]
AttributeError: 'list' object has no attribute 'rjust'

The above is also true when using the Datetime64Formatter directly with values of ndim > 1.

Expected Output

Formatting that takes into account dimensionality:

[' [2018-01-01 00:00:00, 2018-01-01 01:00:00, 201...', ' [2018-01-01 05:00:00, 2018-01-01 06:00:00, 201...']

Output of pd.show_versions()

INSTALLED VERSIONS

commit : db08276
python : 3.8.6.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-54-generic
Version : #60-Ubuntu SMP Fri Nov 6 10:37:59 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.1.3
numpy : 1.19.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.3
setuptools : 49.6.0.post20201009
Cython : None
pytest : 6.1.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.18.1
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 1.0.1
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.5.2
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@BryanCutler BryanCutler added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 9, 2020
@rhshadrach rhshadrach added Datetime Datetime data dtype and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 10, 2020
@jreback jreback added ExtensionArray Extending pandas with custom dtypes or arrays. Output-Formatting __repr__ of pandas objects, to_string labels Dec 22, 2020
@jreback jreback added this to the 1.5 milestone Feb 27, 2022
@mroeschke mroeschke removed this from the 1.5 milestone Aug 15, 2022
@jbrockmendel
Copy link
Member

Can this be reproduced using public APIs? Do you have a 2D EA that is breaking somewhere?

@BryanCutler
Copy link
Contributor Author

Yes it was public APIs for extension arrays, but it was quite some time ago and I haven't check recent versions. Let's close this and I'll reopen if I'm able to confirm it's still an issue.

@BryanCutler
Copy link
Contributor Author

Actually I just tried the code sample in the description with v2.0.3 and got the same error. It's using a datetime array, but produces same formatting error for an extension array.

@BryanCutler BryanCutler reopened this Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype ExtensionArray Extending pandas with custom dtypes or arrays. Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
5 participants