@@ -2472,7 +2472,19 @@ def _check_for_bom(self, first_row):
2472
2472
# return an empty string.
2473
2473
return ["" ]
2474
2474
2475
- def _empty (self , line ):
2475
+ def _is_line_empty (self , line ):
2476
+ """
2477
+ Check if a line is empty or not.
2478
+
2479
+ Parameters
2480
+ ----------
2481
+ line : str, array-like
2482
+ The line of data to check.
2483
+
2484
+ Returns
2485
+ -------
2486
+ boolean : Whether or not the line is empty.
2487
+ """
2476
2488
return not line or all (not x for x in line )
2477
2489
2478
2490
def _next_line (self ):
@@ -2485,11 +2497,12 @@ def _next_line(self):
2485
2497
line = self ._check_comments ([self .data [self .pos ]])[0 ]
2486
2498
self .pos += 1
2487
2499
# either uncommented or blank to begin with
2488
- if not self .skip_blank_lines and (self ._empty (self .data [
2489
- self .pos - 1 ]) or line ):
2500
+ if (not self .skip_blank_lines and
2501
+ (self ._is_line_empty (
2502
+ self .data [self .pos - 1 ]) or line )):
2490
2503
break
2491
2504
elif self .skip_blank_lines :
2492
- ret = self ._check_empty ([line ])
2505
+ ret = self ._remove_empty_lines ([line ])
2493
2506
if ret :
2494
2507
line = ret [0 ]
2495
2508
break
@@ -2508,12 +2521,12 @@ def _next_line(self):
2508
2521
line = self ._check_comments ([orig_line ])[0 ]
2509
2522
2510
2523
if self .skip_blank_lines :
2511
- ret = self ._check_empty ([line ])
2524
+ ret = self ._remove_empty_lines ([line ])
2512
2525
2513
2526
if ret :
2514
2527
line = ret [0 ]
2515
2528
break
2516
- elif self ._empty (orig_line ) or line :
2529
+ elif self ._is_line_empty (orig_line ) or line :
2517
2530
break
2518
2531
2519
2532
# This was the first line of the file,
@@ -2604,7 +2617,22 @@ def _check_comments(self, lines):
2604
2617
ret .append (rl )
2605
2618
return ret
2606
2619
2607
- def _check_empty (self , lines ):
2620
+ def _remove_empty_lines (self , lines ):
2621
+ """
2622
+ Iterate through the lines and remove any that are
2623
+ either empty or contain only one whitespace value
2624
+
2625
+ Parameters
2626
+ ----------
2627
+ lines : array-like
2628
+ The array of lines that we are to filter.
2629
+
2630
+ Returns
2631
+ -------
2632
+ filtered_lines : array-like
2633
+ The same array of lines with the "empty" ones removed.
2634
+ """
2635
+
2608
2636
ret = []
2609
2637
for l in lines :
2610
2638
# Remove empty lines and lines with only one whitespace value
@@ -2844,7 +2872,7 @@ def _get_lines(self, rows=None):
2844
2872
2845
2873
lines = self ._check_comments (lines )
2846
2874
if self .skip_blank_lines :
2847
- lines = self ._check_empty (lines )
2875
+ lines = self ._remove_empty_lines (lines )
2848
2876
lines = self ._check_thousands (lines )
2849
2877
return self ._check_decimal (lines )
2850
2878
0 commit comments