-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: DataFrame.insert with allow_duplicates=True fails when already duplicates present #14291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@mbochk That looks like a bug indeed. Thanks for reporting |
I looked into this and discovered that the problem is in frame.py, in the _sanitize_column method. Here's the relevant code: # broadcast across multiple columns if necessary
if key in self.columns and value.ndim == 1:
if (not self.columns.is_unique or
isinstance(self.columns, MultiIndex)):
existing_piece = self[key]
if isinstance(existing_piece, DataFrame):
value = np.tile(value, (len(existing_piece.columns), 1)) On the third time |
What happens here is needed when you are setting a certain column (eg |
…olumns in a dataframe closes pandas-dev#14291 closes pandas-dev#14431 (cherry picked from commit 2e77536)
upon DataFrame.insert option allow_duplicates works, but only only once.
When i have 2 columns with same name, additon of third throws
Code Sample, a copy-pastable example if possible
Expected Output
zxc qwe qwe
0 1 1 1
1 2 2 2
2 3 3 3
3 4 4 4
output of
pd.show_versions()
commit: None
python: 2.7.12.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 58 Stepping 9, GenuineIntel
byteorder: little
LC_ALL: None
LANG: ru_RU
pandas: 0.18.1
nose: 1.3.7
pip: 8.1.2
setuptools: 25.1.6
Cython: 0.24.1
numpy: 1.11.1
scipy: 0.18.0
statsmodels: 0.6.1
xarray: None
IPython: 5.1.0
sphinx: 1.4.6
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.6.1
blosc: None
bottleneck: 1.0.0
tables: 3.2.2
numexpr: 2.6.1
matplotlib: 1.5.3
openpyxl: 2.3.2
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: 0.9.2
lxml: 3.6.4
bs4: 4.4.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.13
pymysql: 0.7.6.None
psycopg2: None
jinja2: 2.8
boto: 2.40.0
pandas_datareader: None
<\details>
The text was updated successfully, but these errors were encountered: