Skip to content

Commit 751119f

Browse files
gfyoungjreback
authored andcommitted
MAINT: Refactor Python engine empty line funcs (pandas-dev#15946)
The Python engine's _empty and _check_empty methods were uninformative and undocumented. This commit renames them to _is_line_empty and _remove_empty_lines respectively and provides appropriate documentation.
1 parent b28eb10 commit 751119f

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

pandas/io/parsers.py

+36-8
Original file line numberDiff line numberDiff line change
@@ -2472,7 +2472,19 @@ def _check_for_bom(self, first_row):
24722472
# return an empty string.
24732473
return [""]
24742474

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+
"""
24762488
return not line or all(not x for x in line)
24772489

24782490
def _next_line(self):
@@ -2485,11 +2497,12 @@ def _next_line(self):
24852497
line = self._check_comments([self.data[self.pos]])[0]
24862498
self.pos += 1
24872499
# 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)):
24902503
break
24912504
elif self.skip_blank_lines:
2492-
ret = self._check_empty([line])
2505+
ret = self._remove_empty_lines([line])
24932506
if ret:
24942507
line = ret[0]
24952508
break
@@ -2508,12 +2521,12 @@ def _next_line(self):
25082521
line = self._check_comments([orig_line])[0]
25092522

25102523
if self.skip_blank_lines:
2511-
ret = self._check_empty([line])
2524+
ret = self._remove_empty_lines([line])
25122525

25132526
if ret:
25142527
line = ret[0]
25152528
break
2516-
elif self._empty(orig_line) or line:
2529+
elif self._is_line_empty(orig_line) or line:
25172530
break
25182531

25192532
# This was the first line of the file,
@@ -2604,7 +2617,22 @@ def _check_comments(self, lines):
26042617
ret.append(rl)
26052618
return ret
26062619

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+
26082636
ret = []
26092637
for l in lines:
26102638
# Remove empty lines and lines with only one whitespace value
@@ -2844,7 +2872,7 @@ def _get_lines(self, rows=None):
28442872

28452873
lines = self._check_comments(lines)
28462874
if self.skip_blank_lines:
2847-
lines = self._check_empty(lines)
2875+
lines = self._remove_empty_lines(lines)
28482876
lines = self._check_thousands(lines)
28492877
return self._check_decimal(lines)
28502878

0 commit comments

Comments
 (0)