Skip to content

Commit f8fc64e

Browse files
committed
Merge pull request #5674 from jreback/hdf_doc
BUG: HDFStore improperly inferring a freq on datetimeindexes
2 parents fb4415e + dffc21f commit f8fc64e

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

doc/source/io.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -2089,6 +2089,7 @@ dict:
20892089

20902090
.. ipython:: python
20912091
2092+
np.random.seed(1234)
20922093
index = date_range('1/1/2000', periods=8)
20932094
s = Series(randn(5), index=['a', 'b', 'c', 'd', 'e'])
20942095
df = DataFrame(randn(8, 3), index=index,
@@ -2513,14 +2514,15 @@ be data_columns
25132514
df_dc.ix[4:6,'string'] = np.nan
25142515
df_dc.ix[7:9,'string'] = 'bar'
25152516
df_dc['string2'] = 'cool'
2517+
df_dc.ix[1:3,['B','C']] = 1.0
25162518
df_dc
25172519
25182520
# on-disk operations
25192521
store.append('df_dc', df_dc, data_columns = ['B', 'C', 'string', 'string2'])
25202522
store.select('df_dc', [ Term('B>0') ])
25212523
25222524
# getting creative
2523-
store.select('df_dc', ['B > 0', 'C > 0', 'string == foo'])
2525+
store.select('df_dc', 'B > 0 & C > 0 & string == foo')
25242526
25252527
# this is in-memory version of this type of selection
25262528
df_dc[(df_dc.B > 0) & (df_dc.C > 0) & (df_dc.string == 'foo')]

pandas/io/pytables.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1434,12 +1434,11 @@ def convert(self, values, nan_rep, encoding):
14341434
self.values = Index(values, **kwargs)
14351435
except:
14361436

1437-
# if the output freq is different that what we recorded, then infer
1438-
# it
1437+
# if the output freq is different that what we recorded,
1438+
# it should be None (see also 'doc example part 2')
14391439
if 'freq' in kwargs:
1440-
kwargs['freq'] = 'infer'
1441-
self.values = Index(
1442-
_maybe_convert(values, self.kind, encoding), **kwargs)
1440+
kwargs['freq'] = None
1441+
self.values = Index(values, **kwargs)
14431442

14441443
# set the timezone if indicated
14451444
# we stored in utc, so reverse to local timezone

pandas/io/tests/test_pytables.py

+23
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,29 @@ def check_col(key,name,size):
13271327
df_dc.string == 'foo')]
13281328
tm.assert_frame_equal(result, expected)
13291329

1330+
with ensure_clean_store(self.path) as store:
1331+
# doc example part 2
1332+
np.random.seed(1234)
1333+
index = date_range('1/1/2000', periods=8)
1334+
df_dc = DataFrame(np.random.randn(8, 3), index=index,
1335+
columns=['A', 'B', 'C'])
1336+
df_dc['string'] = 'foo'
1337+
df_dc.ix[4:6,'string'] = np.nan
1338+
df_dc.ix[7:9,'string'] = 'bar'
1339+
df_dc.ix[:,['B','C']] = df_dc.ix[:,['B','C']].abs()
1340+
df_dc['string2'] = 'cool'
1341+
1342+
# on-disk operations
1343+
store.append('df_dc', df_dc, data_columns = ['B', 'C', 'string', 'string2'])
1344+
1345+
result = store.select('df_dc', [ Term('B>0') ])
1346+
expected = df_dc[df_dc.B>0]
1347+
tm.assert_frame_equal(result,expected)
1348+
1349+
result = store.select('df_dc', ['B > 0', 'C > 0', 'string == "foo"'])
1350+
expected = df_dc[(df_dc.B > 0) & (df_dc.C > 0) & (df_dc.string == 'foo')]
1351+
tm.assert_frame_equal(result,expected)
1352+
13301353
def test_create_table_index(self):
13311354

13321355
with ensure_clean_store(self.path) as store:

0 commit comments

Comments
 (0)