@@ -324,7 +324,8 @@ class ReaderMixin {
324324 read_options_ (read_options),
325325 parse_options_(parse_options),
326326 convert_options_(convert_options),
327- num_rows_seen_(count_rows ? 1 : -1 ),
327+ count_rows_(count_rows),
328+ num_rows_seen_(count_rows_ ? 1 : -1 ),
328329 input_(std::move(input)) {}
329330
330331 protected:
@@ -345,7 +346,7 @@ class ReaderMixin {
345346 " rows from CSV file, "
346347 " either file is too short or header is larger than block size" );
347348 }
348- if (num_rows_seen_ >= 0 ) {
349+ if (count_rows_ ) {
349350 num_rows_seen_ = num_skipped_rows;
350351 }
351352 }
@@ -379,7 +380,7 @@ class ReaderMixin {
379380 DCHECK_EQ (static_cast <size_t >(parser.num_cols ()), column_names_.size ());
380381 // Skip parsed header row
381382 data += parsed_size;
382- if (num_rows_seen_ >= 0 ) {
383+ if (count_rows_ ) {
383384 ++num_rows_seen_;
384385 }
385386 }
@@ -498,7 +499,7 @@ class ReaderMixin {
498499 } else {
499500 RETURN_NOT_OK (parser->Parse (views, &parsed_size));
500501 }
501- if (num_rows_seen_ >= 0 ) {
502+ if (count_rows_ ) {
502503 num_rows_seen_ += parser->num_rows ();
503504 }
504505 return ParseResult{std::move (parser), static_cast <int64_t >(parsed_size)};
@@ -511,7 +512,9 @@ class ReaderMixin {
511512
512513 // Number of columns in the CSV file
513514 int32_t num_csv_cols_ = -1 ;
514- // Number of rows seen in the csv. -1 indicates row counting is disabled
515+ // Whether num_rows_seen_ tracks the number of rows seen in the CSV being parsed
516+ bool count_rows_;
517+ // Number of rows seen in the csv. Not used if count_rows is false
515518 int64_t num_rows_seen_;
516519 // Column names in the CSV file
517520 std::vector<std::string> column_names_;
0 commit comments