Fix setting dataframe column to 2d array with more than one col
State: closed

- [ ] closes #40827
- [ ] tests added / passed
- [ ] Ensure all linting tests pass, see [here](https://pandas.pydata.org/pandas-docs/dev/development/contributing.html#code-standards) for how to run them

I throw a value error when a dataframe column is assigned to an object with `ndim == 2` with more than one column.
I have added a test to test dataframe column assignment to an array with more than one 'column' and a test to show that assignment still works with an array with only one 'column'. 

The tests I added pass but I am unsure why ~600 existing tests fail when I run the entire suite (whether I have my change or not). I doubt the tests are failing because of something on my machine but I want to see if that's the case anyway.

~500 linting tests fail as well when I run `./ci/code_checks.sh`


Labels:

Comments:
@phofl I've made the changes you've requested and fixed the issue causing most tests to fail. There are still some issues though that I need some help with:
1. In `pandas/core/frame.py`, line 3739 and 3740 have been added to cause tests in `pandas/tests/indexing/multiindex/test_setitem.py`, `pandas/tests/plotting/frame/test_frame_color.py` and `pandas/tests/frame/test_nonunique_indexes.py` but I don't feel as though this was the best way to get those tests to pass.
2. `test_constructor_cast_failure` in `pandas/tests/frame/test_constructors.py` fails and I think we should we removing that test because it goes against the fix in this PR?
3. A lot of linting tests fail ...
Did you setup your env recently or some time in the past? the pre-commit ci task passes, also mypy, so this looks like it is a problem on your machine

``test_constructor_cast_failure`` looks good to me, you should be able to store lists in df columns

You have to check for duplicates in columns somewhere, had this problem at different places too. We have some functions for this like ``check_setitem_lengths``, maybe you can find something there. I've added one dealing with duplicates a few weeks back.

Why is the MultiIndex check necessary?
# Current state of affairs:
Scenarios (all of these assume the key already exists in the column).
1. Assigning a dataframe column that has a dataframe inside: E.g. `df = DataFrame(np.random.randn(10, 3), columns=[["a", "a", "b"], [0, 1, 0]])` df["a"] should succeed if it is being assigned to a scalar value, a series/single array (all columns are made to equal that series) or a 2d array with the same number of columns.
2. Assigning a dataframe column that is a duplicate. E.g. `df = DataFrame(np.random.randn(10, 3), columns=[["a", "a", "b")` df["a"] should succeed if it is being assigned to a scalar value, a series/single array or a 2d array with te same number of columns.
3. Assigning a dataframe column that is just a simple column. E.g. `df = DataFrame(np.random.randn(10, 2), columns=[["a",  "b") df["a"] should succeed if it is being assigned to a scalar value, a series/single array.

The current code fails with scenario 1 but if you remove the `or len(self.columns.get_indexer_for([key])) != value.shape[1]` predicate on line `3476`, it will pass and scenario 2 will fail.

Line `3471` was added to make a test pass. I don't really know why a list of lists was allowed to pass but an ndarray of lists not allowed to be assigned to a column.

I have removed the multiindex check and fixed the environment issue.

Some guidance would be appreciated! I'm not sure where to go from here. @phofl 
I think this may be slightly complicated for a first issue 😅
Closed in favour of #41193
pls just one PR per issue - simple push changes to the existing PR 

ok that you have created a new one