Skip to content

BUG: Transpose construction/block error with certain dtypes #16362

Closed
@RobinFiveWords

Description

@RobinFiveWords

Code Sample, a copy-pastable example if possible

import pandas as pd
from io import StringIO

data = "dt1,obj1,obj2,obj3,num1\n,a,c,e,0\n,b,d,f,1"

df1 = pd.read_csv(StringIO(data), dtype={'num1': float}, parse_dates=['dt1'])
df2 = pd.read_csv(StringIO(data), dtype={'num1': int}, parse_dates=['dt1'])

print(df1.T)
print(df2.T)  # ValueError in v0.20.1 but not v0.19.2

Problem description

Tried to provide a minimal example here. I originally encountered the error with a dataframe containing datetime, object, and int dtypes, and triggered it with this...

df.iloc[[0, -1]].T

...and even found things like this:

df.iloc[[0, 1], [2, 3, 4, 9]].T  # okay
df.iloc[[0, 1], [2, 3, 4, 4, 9]].T  # ValueError
df.iloc[[0, 1], [2, 3, 4, 9, 4]].T  # okay (?!)

Expected Output

    0    1

dt1 NaT NaT
obj1 a b
obj2 c d
obj3 e f
num1 0 1
0 1
dt1 NaT NaT
obj1 a b
obj2 c d
obj3 e f
num1 0 1

Output of pd.show_versions()

# Paste the output here pd.show_versions() here INSTALLED VERSIONS ------------------ commit: None python: 3.6.0.final.0 python-bits: 64 OS: Windows OS-release: 7 machine: AMD64 processor: Intel64 Family 6 Model 61 Stepping 4, GenuineIntel byteorder: little LC_ALL: None LANG: None LOCALE: None.None

pandas: 0.20.1
pytest: 3.0.5
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.25.2
numpy: 1.12.1
scipy: 0.19.0
xarray: None
IPython: 5.1.0
sphinx: 1.5.1
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: 1.2.0
tables: 3.2.2
numexpr: 2.6.2
feather: None
matplotlib: 2.0.1
openpyxl: 2.4.1
xlrd: 1.0.0
xlwt: 1.2.0
xlsxwriter: 0.9.6
lxml: 3.7.2
bs4: 4.5.3
html5lib: None
sqlalchemy: 1.1.5
pymysql: None
psycopg2: None
jinja2: 2.9.4
s3fs: None
pandas_gbq: None
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugRegressionFunctionality that used to work in a prior pandas version

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions