pydata/pandas — pull request #3683 by jreback (2013-05-22 14:44:07+00:00)
Title: BUG: allow insertion/deletion of columns in non-unique column DataFrames

closes #3679

Here's example of various operations

```
In [3]: df = DataFrame([[1,1,1,5],[1,1,2,5],[2,1,3,5]],
columns=['foo','bar','foo','hello'])

In [27]: df.columns.is_unique
Out[27]: False

In [4]: # insert

In [5]: df['string'] = 'bah'

In [6]: df
Out[6]:
foo bar foo hello string
0 1 1 1 5 bah
1 1 1 2 5 bah
2 2 1 3 5 bah

In [7]: # insert same dtype

In [8]: df['foo2'] = 3

In [9]: df
Out[9]:
foo bar foo hello string foo2
0 1 1 1 5 bah 3
1 1 1 2 5 bah 3
2 2 1 3 5 bah 3

In [10]: # delete (non dup)

In [11]: del df['bar']

In [12]: df
Out[12]:
foo foo hello string foo2
0 1 1 5 bah 3
1 1 2 5 bah 3
2 2 3 5 bah 3

In [13]: # try to delete again (its not consolidated)

In [14]: del df['hello']

In [15]: df
Out[15]:
foo foo string foo2
0 1 1 bah 3
1 1 2 bah 3
2 2 3 bah 3

In [16]: # insert

In [17]: df.insert(2,'new_col',5.)

In [18]: df
Out[18]:
foo foo new_col string foo2
0 1 1 5 bah 3
1 1 2 5 bah 3
2 2 3 5 bah 3
```

This is the current default behavior now
```
In [19]: # insert a dup

In [20]: df.insert(2,'new_col',4.)
Exception: cannot insert new_col, already exists

In [21]: # insert a dup

In [22]: df.insert(2,'new_col',4.,allow_duplicates=True)

In [23]: df
Out[23]:
foo foo new_col new_col string foo2
0 1 1 4 5 bah 3
1 1 2 4 5 bah 3
2 2 3 4 5 bah 3
```

```
In [24]: # delete (dup)

In [25]: del df['foo']

In [26]: df
Out[26]:
new_col new_col string foo2
0 4 5 bah 3
1 4 5 bah 3
2 4 5 bah 3
```