Skip to content

Commit d420334

Browse files
committed
TST: test coverage and concat bugfix
1 parent 8afa1b5 commit d420334

File tree

3 files changed

+54
-18
lines changed

3 files changed

+54
-18
lines changed

RELEASE.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ pandas 0.7.0
3333
relational-algebra operations. Refactored existing join methods to use the
3434
new infrastructure, resulting in substantial performance gains (GH #220,
3535
#249, #267)
36+
- New ``concatenate`` function for concatenating DataFrame or Panel objects
37+
along an axis. Can form union or intersection of the other axes
3638
- Handle differently-indexed output values in ``DataFrame.apply`` (GH #498)
3739
- Can pass list of dicts (e.g., a list of shallow JSON objects) to DataFrame
3840
constructor (GH #526)
@@ -49,6 +51,9 @@ pandas 0.7.0
4951
- Add attribute-based item access to ``Panel`` and add IPython completion (PR
5052
#554)
5153
- Add ``logy`` option to ``Series.plot`` for log-scaling on the Y axis
54+
- Can pass multiple DataFrames to ``DataFrame.join`` to join on index (GH #115)
55+
- Can pass multiple Panels to ``Panel.join`` (GH #115)
56+
- Can pass multiple DataFrames to `DataFrame.append` to concatenate (stack)
5257

5358
**API Changes**
5459

pandas/tools/merge.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -721,8 +721,6 @@ def _concat_single_item(self, item):
721721
all_values = []
722722
dtypes = set()
723723
for obj in self.objs:
724-
if len(obj) == 0:
725-
continue
726724
try:
727725
values = obj._data.get(item)
728726
dtypes.add(values.dtype)
@@ -785,27 +783,13 @@ def _get_new_axes(self):
785783

786784
return new_axes
787785

788-
def _get_obj_constructor(self):
789-
# SparseDataFrame causes us some headache here
790-
791-
# check that there's only one type present
792-
obj_types = set(type(df) for df in self.objs)
793-
if len(obj_types) > 1:
794-
raise Exception('Can only concatenate like-typed objects, found %s'
795-
% obj_types)
796-
797-
return self.objs[0]._constructor
798-
799786
def _maybe_check_integrity(self, concat_index):
800787
if self.verify_integrity:
801788
if not concat_index._verify_integrity():
802789
overlap = concat_index.get_duplicates()
803790
raise Exception('Indexes have overlapping values: %s'
804791
% str(overlap))
805792

806-
@cache_readonly
807-
def _all_indexes_same(self):
808-
return _all_indexes_same([df.columns for df in self.objs])
809793

810794
def _concat_frames_hierarchical(frames, keys, groupings, axis=0):
811795
names = [ping.name for ping in groupings]

pandas/tools/tests/test_merge.py

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import random
77

88
from pandas import *
9-
from pandas.tools.merge import merge
9+
from pandas.tools.merge import merge, concat
1010
from pandas.util.testing import (assert_frame_equal, assert_series_equal,
1111
assert_almost_equal, rands)
1212
import pandas._tseries as lib
@@ -741,6 +741,40 @@ def test_append_missing_column_proper_upcast(self):
741741
self.assert_(appended['A'].dtype == 'f8')
742742
self.assert_(appended['B'].dtype == 'O')
743743

744+
def test_crossed_dtypes_weird_corner(self):
745+
columns = ['A', 'B', 'C', 'D']
746+
df1 = DataFrame({'A' : np.array([1, 2, 3, 4], dtype='f8'),
747+
'B' : np.array([1, 2, 3, 4], dtype='i8'),
748+
'C' : np.array([1, 2, 3, 4], dtype='f8'),
749+
'D' : np.array([1, 2, 3, 4], dtype='i8')},
750+
columns=columns)
751+
752+
df2 = DataFrame({'A' : np.array([1, 2, 3, 4], dtype='i8'),
753+
'B' : np.array([1, 2, 3, 4], dtype='f8'),
754+
'C' : np.array([1, 2, 3, 4], dtype='i8'),
755+
'D' : np.array([1, 2, 3, 4], dtype='f8')},
756+
columns=columns)
757+
758+
appended = df1.append(df2, ignore_index=True)
759+
expected = DataFrame(np.concatenate([df1.values, df2.values], axis=0),
760+
columns=columns)
761+
tm.assert_frame_equal(appended, expected)
762+
763+
def test_handle_empty_objects(self):
764+
df = DataFrame(np.random.randn(10, 4), columns=list('abcd'))
765+
766+
baz = df[:5]
767+
baz['foo'] = 'bar'
768+
empty = df[5:5]
769+
770+
frames = [baz, empty, empty, df[5:]]
771+
concatted = concat(frames, axis=0)
772+
773+
expected = df.ix[:, ['a', 'b', 'c', 'd', 'foo']]
774+
expected['foo'] = expected['foo'].astype('O')
775+
expected['foo'][:5] = 'bar'
776+
777+
tm.assert_frame_equal(concatted, expected)
744778

745779
def test_panel_join(self):
746780
panel = tm.makePanel()
@@ -800,10 +834,23 @@ def test_panel_join_many(self):
800834
joined = panels[0].join(panels[1:])
801835
tm.assert_panel_equal(joined, panel)
802836

837+
panels = [panel.ix[:2, :-5], panel.ix[2:6, 2:], panel.ix[6:, 5:-7]]
838+
839+
data_dict = {}
840+
for p in panels:
841+
data_dict.update(p.iterkv())
842+
843+
joined = panels[0].join(panels[1:], how='inner')
844+
expected = Panel.from_dict(data_dict, intersect=True)
845+
tm.assert_panel_equal(joined, expected)
846+
847+
joined = panels[0].join(panels[1:], how='outer')
848+
expected = Panel.from_dict(data_dict, intersect=False)
849+
tm.assert_panel_equal(joined, expected)
850+
803851
if __name__ == '__main__':
804852
import nose
805853
nose.runmodule(argv=[__file__,'-vvs','-x','--pdb', '--pdb-failure'],
806854
exit=False)
807855

808856

809-

0 commit comments

Comments
 (0)