Skip to content

BUG: Duplicate indexes with and empty DataFrame.from_records will return a correct frame (GH3562) #3564

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

Merged
merged 1 commit into from
May 10, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pandas 0.11.1
- ``.loc`` was not raising when passed an integer list (GH3449_)
- Unordered time series selection was misbehaving when using label slicing (GH3448_)
- Duplicate indexes with getitem will return items in the correct order (GH3455_, GH3457_)
- Duplicate indexes with and empty DataFrame.from_records will return a correct frame (GH3562_)
- Fix sorting in a frame with a list of columns which contains datetime64[ns] dtypes (GH3461_)
- DataFrames fetched via FRED now handle '.' as a NaN. (GH3469_)
- Fix regression in a DataFrame apply with axis=1, objects were not being converted back
Expand Down Expand Up @@ -137,6 +138,7 @@ pandas 0.11.1
.. _GH3495: https://github.com/pydata/pandas/issues/3495
.. _GH3492: https://github.com/pydata/pandas/issues/3492
.. _GH3552: https://github.com/pydata/pandas/issues/3552
.. _GH3562: https://github.com/pydata/pandas/issues/3562
.. _GH3493: https://github.com/pydata/pandas/issues/3493


Expand Down
3 changes: 2 additions & 1 deletion pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -1960,7 +1960,8 @@ def form_blocks(arrays, names, axes):
items = axes[0]

if len(arrays) < len(items):
extra_items = items - Index(names)
nn = set(names)
extra_items = Index([ i for i in items if i not in nn ])
else:
extra_items = []

Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3518,6 +3518,16 @@ def test_from_records_misc_brokenness(self):
results = df2_obj.get_dtype_counts()
expected = Series({ 'datetime64[ns]' : 1, 'int64' : 1 })

def test_from_records_empty(self):
# 3562
result = DataFrame.from_records([], columns=['a','b','c'])
expected = DataFrame(columns=['a','b','c'])
assert_frame_equal(result, expected)

result = DataFrame.from_records([], columns=['a','b','b'])
expected = DataFrame(columns=['a','b','b'])
assert_frame_equal(result, expected)

def test_to_records_floats(self):
df = DataFrame(np.random.rand(10, 10))
df.to_records()
Expand Down