Skip to content

Commit 2f250dd

Browse files
committed
Merge pull request #3564 from jreback/GH3562
BUG: Duplicate indexes with and empty DataFrame.from_records will return a correct frame (GH3562)
2 parents 1381c39 + 25ffa14 commit 2f250dd

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

RELEASE.rst

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ pandas 0.11.1
7777
- ``.loc`` was not raising when passed an integer list (GH3449_)
7878
- Unordered time series selection was misbehaving when using label slicing (GH3448_)
7979
- Duplicate indexes with getitem will return items in the correct order (GH3455_, GH3457_)
80+
- Duplicate indexes with and empty DataFrame.from_records will return a correct frame (GH3562_)
8081
- Fix sorting in a frame with a list of columns which contains datetime64[ns] dtypes (GH3461_)
8182
- DataFrames fetched via FRED now handle '.' as a NaN. (GH3469_)
8283
- Fix regression in a DataFrame apply with axis=1, objects were not being converted back
@@ -137,6 +138,7 @@ pandas 0.11.1
137138
.. _GH3495: https://github.com/pydata/pandas/issues/3495
138139
.. _GH3492: https://github.com/pydata/pandas/issues/3492
139140
.. _GH3552: https://github.com/pydata/pandas/issues/3552
141+
.. _GH3562: https://github.com/pydata/pandas/issues/3562
140142
.. _GH3493: https://github.com/pydata/pandas/issues/3493
141143

142144

pandas/core/internals.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1960,7 +1960,8 @@ def form_blocks(arrays, names, axes):
19601960
items = axes[0]
19611961

19621962
if len(arrays) < len(items):
1963-
extra_items = items - Index(names)
1963+
nn = set(names)
1964+
extra_items = Index([ i for i in items if i not in nn ])
19641965
else:
19651966
extra_items = []
19661967

pandas/tests/test_frame.py

+10
Original file line numberDiff line numberDiff line change
@@ -3518,6 +3518,16 @@ def test_from_records_misc_brokenness(self):
35183518
results = df2_obj.get_dtype_counts()
35193519
expected = Series({ 'datetime64[ns]' : 1, 'int64' : 1 })
35203520

3521+
def test_from_records_empty(self):
3522+
# 3562
3523+
result = DataFrame.from_records([], columns=['a','b','c'])
3524+
expected = DataFrame(columns=['a','b','c'])
3525+
assert_frame_equal(result, expected)
3526+
3527+
result = DataFrame.from_records([], columns=['a','b','b'])
3528+
expected = DataFrame(columns=['a','b','b'])
3529+
assert_frame_equal(result, expected)
3530+
35213531
def test_to_records_floats(self):
35223532
df = DataFrame(np.random.rand(10, 10))
35233533
df.to_records()

0 commit comments

Comments
 (0)