piRSquared piRSquared - 3 months ago 17
Python Question

Why does printing a dataframe break python when constructed from numpy empty_like

import numpy as np
import pandas as pd


consider numpy array
a


a = np.array([None, None], dtype=object)
print(a)

[None None]


And
dfa


dfa = pd.DataFrame(a)
print(dfa)

0
0 None
1 None


Now consider numpy array
b


b = np.empty_like(a)
print(b)

[None None]


It appears the same as
a


(a == b).all()

True


THIS! CRASHES MY PYTHON!! BE CAREFUL!!!



dfb = pd.DataFrame(b) # Fine so far
print(dfb.values)

[[None]
[None]]


However

print(dfb) # BOOM!!!

Answer

As reported here, this is a bug, which is fixed in the master branch of pandas / the upcoming 0.19.0 release.