@@ -3264,21 +3264,16 @@ def test_select_iterator(self):
3264
3264
3265
3265
expected = store .select ('df' )
3266
3266
3267
- results = []
3268
- for s in store .select ('df' ,iterator = True ):
3269
- results .append (s )
3267
+ results = [ s for s in store .select ('df' ,iterator = True ) ]
3270
3268
result = concat (results )
3271
3269
tm .assert_frame_equal (expected , result )
3272
- results = []
3273
- for s in store .select ('df' ,chunksize = 100 ):
3274
- results .append (s )
3270
+
3271
+ results = [ s for s in store .select ('df' ,chunksize = 100 ) ]
3275
3272
self .assertEqual (len (results ), 5 )
3276
3273
result = concat (results )
3277
3274
tm .assert_frame_equal (expected , result )
3278
3275
3279
- results = []
3280
- for s in store .select ('df' ,chunksize = 150 ):
3281
- results .append (s )
3276
+ results = [ s for s in store .select ('df' ,chunksize = 150 ) ]
3282
3277
result = concat (results )
3283
3278
tm .assert_frame_equal (result , expected )
3284
3279
@@ -3294,12 +3289,10 @@ def test_select_iterator(self):
3294
3289
df = tm .makeTimeDataFrame (500 )
3295
3290
df .to_hdf (path ,'df' ,format = 'table' )
3296
3291
3297
- results = []
3298
- for x in read_hdf (path ,'df' ,chunksize = 100 ):
3299
- results .append (x )
3292
+ results = [ s for s in read_hdf (path ,'df' ,chunksize = 100 ) ]
3293
+ result = concat (results )
3300
3294
3301
3295
self .assertEqual (len (results ), 5 )
3302
- result = concat (results )
3303
3296
tm .assert_frame_equal (result , df )
3304
3297
tm .assert_frame_equal (result , read_hdf (path ,'df' ))
3305
3298
@@ -3318,10 +3311,8 @@ def test_select_iterator(self):
3318
3311
# full selection
3319
3312
expected = store .select_as_multiple (
3320
3313
['df1' , 'df2' ], selector = 'df1' )
3321
- results = []
3322
- for s in store .select_as_multiple (
3323
- ['df1' , 'df2' ], selector = 'df1' , chunksize = 150 ):
3324
- results .append (s )
3314
+ results = [ s for s in store .select_as_multiple (
3315
+ ['df1' , 'df2' ], selector = 'df1' , chunksize = 150 ) ]
3325
3316
result = concat (results )
3326
3317
tm .assert_frame_equal (expected , result )
3327
3318
@@ -3335,6 +3326,114 @@ def test_select_iterator(self):
3335
3326
#result = concat(results)
3336
3327
#tm.assert_frame_equal(expected, result)
3337
3328
3329
+ def test_select_iterator_complete_8014 (self ):
3330
+
3331
+ # GH 8014
3332
+ # using iterator and where clause
3333
+ chunksize = 1e4
3334
+
3335
+ # no iterator
3336
+ with ensure_clean_store (self .path ) as store :
3337
+
3338
+ expected = tm .makeTimeDataFrame (100064 , 'S' )
3339
+ _maybe_remove (store , 'df' )
3340
+ store .append ('df' ,expected )
3341
+
3342
+ beg_dt = expected .index [0 ]
3343
+ end_dt = expected .index [- 1 ]
3344
+
3345
+ # select w/o iteration and no where clause works
3346
+ result = store .select ('df' )
3347
+ tm .assert_frame_equal (expected , result )
3348
+
3349
+ # select w/o iterator and where clause, single term, begin
3350
+ # of range, works
3351
+ where = "index >= '%s'" % beg_dt
3352
+ result = store .select ('df' ,where = where )
3353
+ tm .assert_frame_equal (expected , result )
3354
+
3355
+ # select w/o iterator and where clause, single term, end
3356
+ # of range, works
3357
+ where = "index <= '%s'" % end_dt
3358
+ result = store .select ('df' ,where = where )
3359
+ tm .assert_frame_equal (expected , result )
3360
+
3361
+ # select w/o iterator and where clause, inclusive range,
3362
+ # works
3363
+ where = "index >= '%s' & index <= '%s'" % (beg_dt , end_dt )
3364
+ result = store .select ('df' ,where = where )
3365
+ tm .assert_frame_equal (expected , result )
3366
+
3367
+ # with iterator, full range
3368
+ with ensure_clean_store (self .path ) as store :
3369
+
3370
+ expected = tm .makeTimeDataFrame (100064 , 'S' )
3371
+ _maybe_remove (store , 'df' )
3372
+ store .append ('df' ,expected )
3373
+
3374
+ beg_dt = expected .index [0 ]
3375
+ end_dt = expected .index [- 1 ]
3376
+
3377
+ # select w/iterator and no where clause works
3378
+ results = [ s for s in store .select ('df' ,chunksize = chunksize ) ]
3379
+ result = concat (results )
3380
+ tm .assert_frame_equal (expected , result )
3381
+
3382
+ # select w/iterator and where clause, single term, begin of range
3383
+ where = "index >= '%s'" % beg_dt
3384
+ results = [ s for s in store .select ('df' ,where = where ,chunksize = chunksize ) ]
3385
+ result = concat (results )
3386
+ tm .assert_frame_equal (expected , result )
3387
+
3388
+ # select w/iterator and where clause, single term, end of range
3389
+ where = "index <= '%s'" % end_dt
3390
+ results = [ s for s in store .select ('df' ,where = where ,chunksize = chunksize ) ]
3391
+ result = concat (results )
3392
+ tm .assert_frame_equal (expected , result )
3393
+
3394
+ # select w/iterator and where clause, inclusive range
3395
+ where = "index >= '%s' & index <= '%s'" % (beg_dt , end_dt )
3396
+ results = [ s for s in store .select ('df' ,where = where ,chunksize = chunksize ) ]
3397
+ result = concat (results )
3398
+ tm .assert_frame_equal (expected , result )
3399
+
3400
+ def test_select_iterator_non_complete_8014 (self ):
3401
+
3402
+ # GH 8014
3403
+ # using iterator and where clause
3404
+ chunksize = 1e4
3405
+
3406
+ # with iterator, non complete range
3407
+ with ensure_clean_store (self .path ) as store :
3408
+
3409
+ expected = tm .makeTimeDataFrame (100064 , 'S' )
3410
+ _maybe_remove (store , 'df' )
3411
+ store .append ('df' ,expected )
3412
+
3413
+ beg_dt = expected .index [1 ]
3414
+ end_dt = expected .index [- 2 ]
3415
+
3416
+ # select w/iterator and where clause, single term, begin of range
3417
+ where = "index >= '%s'" % beg_dt
3418
+ results = [ s for s in store .select ('df' ,where = where ,chunksize = chunksize ) ]
3419
+ result = concat (results )
3420
+ rexpected = expected [expected .index >= beg_dt ]
3421
+ tm .assert_frame_equal (rexpected , result )
3422
+
3423
+ # select w/iterator and where clause, single term, end of range
3424
+ where = "index <= '%s'" % end_dt
3425
+ results = [ s for s in store .select ('df' ,where = where ,chunksize = chunksize ) ]
3426
+ result = concat (results )
3427
+ rexpected = expected [expected .index <= end_dt ]
3428
+ tm .assert_frame_equal (rexpected , result )
3429
+
3430
+ # select w/iterator and where clause, inclusive range
3431
+ where = "index >= '%s' & index <= '%s'" % (beg_dt , end_dt )
3432
+ results = [ s for s in store .select ('df' ,where = where ,chunksize = chunksize ) ]
3433
+ result = concat (results )
3434
+ rexpected = expected [(expected .index >= beg_dt ) & (expected .index <= end_dt )]
3435
+ tm .assert_frame_equal (rexpected , result )
3436
+
3338
3437
def test_retain_index_attributes (self ):
3339
3438
3340
3439
# GH 3499, losing frequency info on index recreation
0 commit comments