Skip to content

Commit 20eeb12

Browse files
committed
ENH: silently drop None in concat, memoize datetime integers in HDFStore conversion
1 parent fd00bb9 commit 20eeb12

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

pandas/io/pytables.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,14 @@ def _maybe_convert(values, val_kind):
777777

778778
def _get_converter(kind):
779779
if kind == 'datetime':
780-
return datetime.fromtimestamp
780+
cache = {}
781+
def convert_datetime(x):
782+
if x in cache:
783+
return cache[x]
784+
else:
785+
cache[x] = result = datetime.fromtimestamp(x)
786+
return result
787+
return convert_datetime
781788
else: # pragma: no cover
782789
raise ValueError('invalid kind %s' % kind)
783790

pandas/tools/merge.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,8 @@ def concat(objs, axis=0, join='outer', join_axes=None, ignore_index=False,
610610
objs : list or dict of Series, DataFrame, or Panel objects
611611
If a dict is passed, the sorted keys will be used as the `keys`
612612
argument, unless it is passed, in which case the values will be
613-
selected (see below)
613+
selected (see below). Any None objects will be dropped silently unless
614+
they are all None in which case an Exception will be raised
614615
axis : {0, 1, ...}, default 0
615616
The axis to concatenate along
616617
join : {'inner', 'outer'}, default 'outer'
@@ -672,6 +673,12 @@ def __init__(self, objs, axis=0, join='outer', join_axes=None,
672673
keys = sorted(objs)
673674
objs = [objs[k] for k in keys]
674675

676+
# filter Nones
677+
objs = [obj for obj in objs if obj is not None]
678+
679+
if len(objs) == 0:
680+
raise Exception('All objects passed were None')
681+
675682
# consolidate data
676683
for obj in objs:
677684
if isinstance(obj, NDFrame):

pandas/tools/tests/test_merge.py

+7
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,13 @@ def test_concat_single_with_key(self):
10961096
expected = concat([df, df], keys=['foo', 'bar'])
10971097
tm.assert_frame_equal(result, expected[:10])
10981098

1099+
def test_concat_exclude_none(self):
1100+
df = DataFrame(np.random.randn(10, 4))
1101+
1102+
pieces = [df[:5], None, None, df[5:]]
1103+
result = concat(pieces)
1104+
tm.assert_frame_equal(result, df)
1105+
self.assertRaises(Exception, concat, [None, None])
10991106

11001107
if __name__ == '__main__':
11011108
import nose

scripts/hdfstore_panel_perf.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from pandas import *
22
from pandas.util.testing import rands
33

4-
i, j, k = 1, 10000, 500
4+
i, j, k = 7, 771, 5532
55

66
panel = Panel(np.random.randn(i, j, k),
77
items=[rands(10) for _ in xrange(i)],
8-
major_axis=[rands(10) for _ in xrange(j)],
8+
major_axis=DateRange('1/1/2000', periods=j,
9+
offset=datetools.Minute()),
910
minor_axis=[rands(10) for _ in xrange(k)])
1011

1112

0 commit comments

Comments
 (0)