I have the following code:
x = pd.DataFrame(np.zeros((4, 1)), columns=['A'])
y = np.random.randn(4, 2)
x['A'] = y
I expect it to throw an exception because of shape mismatch. But pandas silently accepted the assignment: y's first column is assigned to x.
Is this an intentional design? If yes, what is the rationale behind?
I tried both pandas 0.21 and 0.23.
Thanks for those who tried to help. However, nobody gives a satisfactory answer although the bounty is going to expire.
Let me emphasis what is expected as an answer:
- whether this design is intentional? Is it a bug ? Is it a false design?
- what is the rationale to design it in this way?
Since the bounty is going to expiry, I accepted the most voted answer. But it does not provide a answer to the above questions.
'A'already being a column. For isntance x['B'] = y gives you the expectedValueError: Wrong number of items passed 2, placement implies 1pandasrepository, and it seems like it may be a bug.