Python pandas.compat.next() Examples
The following are 25
code examples of pandas.compat.next().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pandas.compat
, or try the search function
.
Example #1
Source File: parsers.py From recruit with Apache License 2.0 | 6 votes |
def read(self, nrows=None): nrows = _validate_integer('nrows', nrows) ret = self._engine.read(nrows) # May alter columns / col_dict index, columns, col_dict = self._create_index(ret) if index is None: if col_dict: # Any column is actually fine: new_rows = len(compat.next(compat.itervalues(col_dict))) index = RangeIndex(self._currow, self._currow + new_rows) else: new_rows = 0 else: new_rows = len(index) df = DataFrame(col_dict, columns=columns, index=index) self._currow += new_rows if self.squeeze and len(df.columns) == 1: return df[df.columns[0]].copy() return df
Example #2
Source File: parsers.py From recruit with Apache License 2.0 | 6 votes |
def _check_file_or_buffer(self, f, engine): # see gh-16530 if is_file_like(f): next_attr = "__next__" if PY3 else "next" # The C engine doesn't need the file-like to have the "next" or # "__next__" attribute. However, the Python engine explicitly calls # "next(...)" when iterating through such an object, meaning it # needs to have that attribute ("next" for Python 2.x, "__next__" # for Python 3.x) if engine != "c" and not hasattr(f, next_attr): msg = ("The 'python' engine cannot iterate " "through this file buffer.") raise ValueError(msg) return engine
Example #3
Source File: parsers.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def _check_file_or_buffer(self, f, engine): # see gh-16530 if is_file_like(f): next_attr = "__next__" if PY3 else "next" # The C engine doesn't need the file-like to have the "next" or # "__next__" attribute. However, the Python engine explicitly calls # "next(...)" when iterating through such an object, meaning it # needs to have that attribute ("next" for Python 2.x, "__next__" # for Python 3.x) if engine != "c" and not hasattr(f, next_attr): msg = ("The 'python' engine cannot iterate " "through this file buffer.") raise ValueError(msg) return engine
Example #4
Source File: parsers.py From vnpy_crypto with MIT License | 6 votes |
def _check_file_or_buffer(self, f, engine): # see gh-16530 if is_file_like(f): next_attr = "__next__" if PY3 else "next" # The C engine doesn't need the file-like to have the "next" or # "__next__" attribute. However, the Python engine explicitly calls # "next(...)" when iterating through such an object, meaning it # needs to have that attribute ("next" for Python 2.x, "__next__" # for Python 3.x) if engine != "c" and not hasattr(f, next_attr): msg = ("The 'python' engine cannot iterate " "through this file buffer.") raise ValueError(msg) return engine
Example #5
Source File: parsers.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def _check_file_or_buffer(self, f, engine): # see gh-16530 if is_file_like(f): next_attr = "__next__" if PY3 else "next" # The C engine doesn't need the file-like to have the "next" or # "__next__" attribute. However, the Python engine explicitly calls # "next(...)" when iterating through such an object, meaning it # needs to have that attribute ("next" for Python 2.x, "__next__" # for Python 3.x) if engine != "c" and not hasattr(f, next_attr): msg = ("The 'python' engine cannot iterate " "through this file buffer.") raise ValueError(msg) return engine
Example #6
Source File: parsers.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def _check_file_or_buffer(self, f, engine): # see gh-16530 if is_file_like(f): next_attr = "__next__" if PY3 else "next" # The C engine doesn't need the file-like to have the "next" or # "__next__" attribute. However, the Python engine explicitly calls # "next(...)" when iterating through such an object, meaning it # needs to have that attribute ("next" for Python 2.x, "__next__" # for Python 3.x) if engine != "c" and not hasattr(f, next_attr): msg = ("The 'python' engine cannot iterate " "through this file buffer.") raise ValueError(msg) return engine
Example #7
Source File: parsers.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def read(self, nrows=None): nrows = _validate_integer('nrows', nrows) ret = self._engine.read(nrows) # May alter columns / col_dict index, columns, col_dict = self._create_index(ret) if index is None: if col_dict: # Any column is actually fine: new_rows = len(compat.next(compat.itervalues(col_dict))) index = RangeIndex(self._currow, self._currow + new_rows) else: new_rows = 0 else: new_rows = len(index) df = DataFrame(col_dict, columns=columns, index=index) self._currow += new_rows if self.squeeze and len(df.columns) == 1: return df[df.columns[0]].copy() return df
Example #8
Source File: parsers.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def _next_iter_line(self, row_num): """ Wrapper around iterating through `self.data` (CSV source). When a CSV error is raised, we check for specific error messages that allow us to customize the error message displayed to the user. Parameters ---------- row_num : The row number of the line being parsed. """ try: return next(self.data) except csv.Error as e: if self.warn_bad_lines or self.error_bad_lines: msg = str(e) if 'NULL byte' in msg: msg = ('NULL byte detected. This byte ' 'cannot be processed in Python\'s ' 'native csv library at the moment, ' 'so please pass in engine=\'c\' instead') elif 'newline inside string' in msg: msg = ('EOF inside string starting with ' 'line ' + str(row_num)) if self.skipfooter > 0: reason = ('Error could possibly be due to ' 'parsing errors in the skipped footer rows ' '(the skipfooter keyword is only applied ' 'after Python\'s csv library has parsed ' 'all rows).') msg += '. ' + reason self._alert_malformed(msg, row_num) return None
Example #9
Source File: parsers.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def read(self, nrows=None): if nrows is not None: if self.options.get('skipfooter'): raise ValueError('skipfooter not supported for iteration') ret = self._engine.read(nrows) if self.options.get('as_recarray'): return ret # May alter columns / col_dict index, columns, col_dict = self._create_index(ret) if index is None: if col_dict: # Any column is actually fine: new_rows = len(compat.next(compat.itervalues(col_dict))) index = RangeIndex(self._currow, self._currow + new_rows) else: new_rows = 0 else: new_rows = len(index) df = DataFrame(col_dict, columns=columns, index=index) self._currow += new_rows if self.squeeze and len(df.columns) == 1: return df[df.columns[0]].copy() return df
Example #10
Source File: parsers.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def _next_iter_line(self, row_num): """ Wrapper around iterating through `self.data` (CSV source). When a CSV error is raised, we check for specific error messages that allow us to customize the error message displayed to the user. Parameters ---------- row_num : The row number of the line being parsed. """ try: return next(self.data) except csv.Error as e: if self.warn_bad_lines or self.error_bad_lines: msg = str(e) if 'NULL byte' in msg: msg = ('NULL byte detected. This byte ' 'cannot be processed in Python\'s ' 'native csv library at the moment, ' 'so please pass in engine=\'c\' instead') elif 'newline inside string' in msg: msg = ('EOF inside string starting with ' 'line ' + str(row_num)) if self.skipfooter > 0: reason = ('Error could possibly be due to ' 'parsing errors in the skipped footer rows ' '(the skipfooter keyword is only applied ' 'after Python\'s csv library has parsed ' 'all rows).') msg += '. ' + reason self._alert_malformed(msg, row_num) return None
Example #11
Source File: parsers.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def read(self, nrows=None): if nrows is not None: if self.options.get('skipfooter'): raise ValueError('skipfooter not supported for iteration') ret = self._engine.read(nrows) if self.options.get('as_recarray'): return ret # May alter columns / col_dict index, columns, col_dict = self._create_index(ret) if index is None: if col_dict: # Any column is actually fine: new_rows = len(compat.next(compat.itervalues(col_dict))) index = RangeIndex(self._currow, self._currow + new_rows) else: new_rows = 0 else: new_rows = len(index) df = DataFrame(col_dict, columns=columns, index=index) self._currow += new_rows if self.squeeze and len(df.columns) == 1: return df[df.columns[0]].copy() return df
Example #12
Source File: parsers.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def _next_iter_line(self, row_num): """ Wrapper around iterating through `self.data` (CSV source). When a CSV error is raised, we check for specific error messages that allow us to customize the error message displayed to the user. Parameters ---------- row_num : The row number of the line being parsed. """ try: return next(self.data) except csv.Error as e: if self.warn_bad_lines or self.error_bad_lines: msg = str(e) if 'NULL byte' in msg: msg = ('NULL byte detected. This byte ' 'cannot be processed in Python\'s ' 'native csv library at the moment, ' 'so please pass in engine=\'c\' instead') if self.skipfooter > 0: reason = ('Error could possibly be due to ' 'parsing errors in the skipped footer rows ' '(the skipfooter keyword is only applied ' 'after Python\'s csv library has parsed ' 'all rows).') msg += '. ' + reason self._alert_malformed(msg, row_num) return None
Example #13
Source File: parsers.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def read(self, rows=None): try: content = self._get_lines(rows) except StopIteration: if self._first_chunk: content = [] else: raise # done with first read, next time raise StopIteration self._first_chunk = False columns = list(self.orig_names) if not len(content): # pragma: no cover # DataFrame with the right metadata, even though it's length 0 names = self._maybe_dedup_names(self.orig_names) index, columns, col_dict = _get_empty_meta( names, self.index_col, self.index_names, self.dtype) columns = self._maybe_make_multi_index_columns( columns, self.col_names) return index, columns, col_dict # handle new style for names in index count_empty_content_vals = count_empty_vals(content[0]) indexnamerow = None if self.has_index_names and count_empty_content_vals == len(columns): indexnamerow = content[0] content = content[1:] alldata = self._rows_to_cols(content) data = self._exclude_implicit_index(alldata) columns = self._maybe_dedup_names(self.columns) columns, data = self._do_date_conversions(columns, data) data = self._convert_data(data) index, columns = self._make_index(data, alldata, columns, indexnamerow) return index, columns, data
Example #14
Source File: parsers.py From vnpy_crypto with MIT License | 5 votes |
def _next_iter_line(self, row_num): """ Wrapper around iterating through `self.data` (CSV source). When a CSV error is raised, we check for specific error messages that allow us to customize the error message displayed to the user. Parameters ---------- row_num : The row number of the line being parsed. """ try: return next(self.data) except csv.Error as e: if self.warn_bad_lines or self.error_bad_lines: msg = str(e) if 'NULL byte' in msg: msg = ('NULL byte detected. This byte ' 'cannot be processed in Python\'s ' 'native csv library at the moment, ' 'so please pass in engine=\'c\' instead') elif 'newline inside string' in msg: msg = ('EOF inside string starting with ' 'line ' + str(row_num)) if self.skipfooter > 0: reason = ('Error could possibly be due to ' 'parsing errors in the skipped footer rows ' '(the skipfooter keyword is only applied ' 'after Python\'s csv library has parsed ' 'all rows).') msg += '. ' + reason self._alert_malformed(msg, row_num) return None
Example #15
Source File: parsers.py From vnpy_crypto with MIT License | 5 votes |
def read(self, rows=None): try: content = self._get_lines(rows) except StopIteration: if self._first_chunk: content = [] else: raise # done with first read, next time raise StopIteration self._first_chunk = False columns = list(self.orig_names) if not len(content): # pragma: no cover # DataFrame with the right metadata, even though it's length 0 names = self._maybe_dedup_names(self.orig_names) index, columns, col_dict = _get_empty_meta( names, self.index_col, self.index_names, self.dtype) columns = self._maybe_make_multi_index_columns( columns, self.col_names) return index, columns, col_dict # handle new style for names in index count_empty_content_vals = count_empty_vals(content[0]) indexnamerow = None if self.has_index_names and count_empty_content_vals == len(columns): indexnamerow = content[0] content = content[1:] alldata = self._rows_to_cols(content) data = self._exclude_implicit_index(alldata) columns = self._maybe_dedup_names(self.columns) columns, data = self._do_date_conversions(columns, data) data = self._convert_data(data) index, columns = self._make_index(data, alldata, columns, indexnamerow) return index, columns, data
Example #16
Source File: parsers.py From vnpy_crypto with MIT License | 5 votes |
def read(self, nrows=None): nrows = _validate_integer('nrows', nrows) if nrows is not None: if self.options.get('skipfooter'): raise ValueError('skipfooter not supported for iteration') ret = self._engine.read(nrows) # May alter columns / col_dict index, columns, col_dict = self._create_index(ret) if index is None: if col_dict: # Any column is actually fine: new_rows = len(compat.next(compat.itervalues(col_dict))) index = RangeIndex(self._currow, self._currow + new_rows) else: new_rows = 0 else: new_rows = len(index) df = DataFrame(col_dict, columns=columns, index=index) self._currow += new_rows if self.squeeze and len(df.columns) == 1: return df[df.columns[0]].copy() return df
Example #17
Source File: parsers.py From recruit with Apache License 2.0 | 5 votes |
def _next_iter_line(self, row_num): """ Wrapper around iterating through `self.data` (CSV source). When a CSV error is raised, we check for specific error messages that allow us to customize the error message displayed to the user. Parameters ---------- row_num : The row number of the line being parsed. """ try: return next(self.data) except csv.Error as e: if self.warn_bad_lines or self.error_bad_lines: msg = str(e) if 'NULL byte' in msg: msg = ('NULL byte detected. This byte ' 'cannot be processed in Python\'s ' 'native csv library at the moment, ' 'so please pass in engine=\'c\' instead') if self.skipfooter > 0: reason = ('Error could possibly be due to ' 'parsing errors in the skipped footer rows ' '(the skipfooter keyword is only applied ' 'after Python\'s csv library has parsed ' 'all rows).') msg += '. ' + reason self._alert_malformed(msg, row_num) return None
Example #18
Source File: parsers.py From recruit with Apache License 2.0 | 5 votes |
def read(self, rows=None): try: content = self._get_lines(rows) except StopIteration: if self._first_chunk: content = [] else: raise # done with first read, next time raise StopIteration self._first_chunk = False columns = list(self.orig_names) if not len(content): # pragma: no cover # DataFrame with the right metadata, even though it's length 0 names = self._maybe_dedup_names(self.orig_names) index, columns, col_dict = _get_empty_meta( names, self.index_col, self.index_names, self.dtype) columns = self._maybe_make_multi_index_columns( columns, self.col_names) return index, columns, col_dict # handle new style for names in index count_empty_content_vals = count_empty_vals(content[0]) indexnamerow = None if self.has_index_names and count_empty_content_vals == len(columns): indexnamerow = content[0] content = content[1:] alldata = self._rows_to_cols(content) data = self._exclude_implicit_index(alldata) columns = self._maybe_dedup_names(self.columns) columns, data = self._do_date_conversions(columns, data) data = self._convert_data(data) index, columns = self._make_index(data, alldata, columns, indexnamerow) return index, columns, data
Example #19
Source File: parsers.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 4 votes |
def _next_line(self): if isinstance(self.data, list): while self.skipfunc(self.pos): self.pos += 1 while True: try: line = self._check_comments([self.data[self.pos]])[0] self.pos += 1 # either uncommented or blank to begin with if (not self.skip_blank_lines and (self._is_line_empty( self.data[self.pos - 1]) or line)): break elif self.skip_blank_lines: ret = self._remove_empty_lines([line]) if ret: line = ret[0] break except IndexError: raise StopIteration else: while self.skipfunc(self.pos): self.pos += 1 next(self.data) while True: orig_line = self._next_iter_line(row_num=self.pos + 1) self.pos += 1 if orig_line is not None: line = self._check_comments([orig_line])[0] if self.skip_blank_lines: ret = self._remove_empty_lines([line]) if ret: line = ret[0] break elif self._is_line_empty(orig_line) or line: break # This was the first line of the file, # which could contain the BOM at the # beginning of it. if self.pos == 1: line = self._check_for_bom(line) self.line_pos += 1 self.buf.append(line) return line
Example #20
Source File: parsers.py From vnpy_crypto with MIT License | 4 votes |
def _next_line(self): if isinstance(self.data, list): while self.skipfunc(self.pos): self.pos += 1 while True: try: line = self._check_comments([self.data[self.pos]])[0] self.pos += 1 # either uncommented or blank to begin with if (not self.skip_blank_lines and (self._is_line_empty( self.data[self.pos - 1]) or line)): break elif self.skip_blank_lines: ret = self._remove_empty_lines([line]) if ret: line = ret[0] break except IndexError: raise StopIteration else: while self.skipfunc(self.pos): self.pos += 1 next(self.data) while True: orig_line = self._next_iter_line(row_num=self.pos + 1) self.pos += 1 if orig_line is not None: line = self._check_comments([orig_line])[0] if self.skip_blank_lines: ret = self._remove_empty_lines([line]) if ret: line = ret[0] break elif self._is_line_empty(orig_line) or line: break # This was the first line of the file, # which could contain the BOM at the # beginning of it. if self.pos == 1: line = self._check_for_bom(line) self.line_pos += 1 self.buf.append(line) return line
Example #21
Source File: parsers.py From Splunking-Crime with GNU Affero General Public License v3.0 | 4 votes |
def read(self, rows=None): try: content = self._get_lines(rows) except StopIteration: if self._first_chunk: content = [] else: raise # done with first read, next time raise StopIteration self._first_chunk = False columns = list(self.orig_names) if not len(content): # pragma: no cover # DataFrame with the right metadata, even though it's length 0 names = self._maybe_dedup_names(self.orig_names) index, columns, col_dict = _get_empty_meta( names, self.index_col, self.index_names, self.dtype) columns = self._maybe_make_multi_index_columns( columns, self.col_names) return index, columns, col_dict # handle new style for names in index count_empty_content_vals = count_empty_vals(content[0]) indexnamerow = None if self.has_index_names and count_empty_content_vals == len(columns): indexnamerow = content[0] content = content[1:] alldata = self._rows_to_cols(content) data = self._exclude_implicit_index(alldata) columns = self._maybe_dedup_names(self.columns) columns, data = self._do_date_conversions(columns, data) data = self._convert_data(data) if self.as_recarray: return self._to_recarray(data, columns) index, columns = self._make_index(data, alldata, columns, indexnamerow) return index, columns, data
Example #22
Source File: parsers.py From Splunking-Crime with GNU Affero General Public License v3.0 | 4 votes |
def _next_line(self): if isinstance(self.data, list): while self.skipfunc(self.pos): self.pos += 1 while True: try: line = self._check_comments([self.data[self.pos]])[0] self.pos += 1 # either uncommented or blank to begin with if (not self.skip_blank_lines and (self._is_line_empty( self.data[self.pos - 1]) or line)): break elif self.skip_blank_lines: ret = self._remove_empty_lines([line]) if ret: line = ret[0] break except IndexError: raise StopIteration else: while self.skipfunc(self.pos): self.pos += 1 next(self.data) while True: orig_line = self._next_iter_line(row_num=self.pos + 1) self.pos += 1 if orig_line is not None: line = self._check_comments([orig_line])[0] if self.skip_blank_lines: ret = self._remove_empty_lines([line]) if ret: line = ret[0] break elif self._is_line_empty(orig_line) or line: break # This was the first line of the file, # which could contain the BOM at the # beginning of it. if self.pos == 1: line = self._check_for_bom(line) self.line_pos += 1 self.buf.append(line) return line
Example #23
Source File: parsers.py From recruit with Apache License 2.0 | 4 votes |
def _next_line(self): if isinstance(self.data, list): while self.skipfunc(self.pos): self.pos += 1 while True: try: line = self._check_comments([self.data[self.pos]])[0] self.pos += 1 # either uncommented or blank to begin with if (not self.skip_blank_lines and (self._is_line_empty( self.data[self.pos - 1]) or line)): break elif self.skip_blank_lines: ret = self._remove_empty_lines([line]) if ret: line = ret[0] break except IndexError: raise StopIteration else: while self.skipfunc(self.pos): self.pos += 1 next(self.data) while True: orig_line = self._next_iter_line(row_num=self.pos + 1) self.pos += 1 if orig_line is not None: line = self._check_comments([orig_line])[0] if self.skip_blank_lines: ret = self._remove_empty_lines([line]) if ret: line = ret[0] break elif self._is_line_empty(orig_line) or line: break # This was the first line of the file, # which could contain the BOM at the # beginning of it. if self.pos == 1: line = self._check_for_bom(line) self.line_pos += 1 self.buf.append(line) return line
Example #24
Source File: parsers.py From elasticintel with GNU General Public License v3.0 | 4 votes |
def read(self, rows=None): try: content = self._get_lines(rows) except StopIteration: if self._first_chunk: content = [] else: raise # done with first read, next time raise StopIteration self._first_chunk = False columns = list(self.orig_names) if not len(content): # pragma: no cover # DataFrame with the right metadata, even though it's length 0 names = self._maybe_dedup_names(self.orig_names) index, columns, col_dict = _get_empty_meta( names, self.index_col, self.index_names, self.dtype) columns = self._maybe_make_multi_index_columns( columns, self.col_names) return index, columns, col_dict # handle new style for names in index count_empty_content_vals = count_empty_vals(content[0]) indexnamerow = None if self.has_index_names and count_empty_content_vals == len(columns): indexnamerow = content[0] content = content[1:] alldata = self._rows_to_cols(content) data = self._exclude_implicit_index(alldata) columns = self._maybe_dedup_names(self.columns) columns, data = self._do_date_conversions(columns, data) data = self._convert_data(data) if self.as_recarray: return self._to_recarray(data, columns) index, columns = self._make_index(data, alldata, columns, indexnamerow) return index, columns, data
Example #25
Source File: parsers.py From elasticintel with GNU General Public License v3.0 | 4 votes |
def _next_line(self): if isinstance(self.data, list): while self.skipfunc(self.pos): self.pos += 1 while True: try: line = self._check_comments([self.data[self.pos]])[0] self.pos += 1 # either uncommented or blank to begin with if (not self.skip_blank_lines and (self._is_line_empty( self.data[self.pos - 1]) or line)): break elif self.skip_blank_lines: ret = self._remove_empty_lines([line]) if ret: line = ret[0] break except IndexError: raise StopIteration else: while self.skipfunc(self.pos): self.pos += 1 next(self.data) while True: orig_line = self._next_iter_line(row_num=self.pos + 1) self.pos += 1 if orig_line is not None: line = self._check_comments([orig_line])[0] if self.skip_blank_lines: ret = self._remove_empty_lines([line]) if ret: line = ret[0] break elif self._is_line_empty(orig_line) or line: break # This was the first line of the file, # which could contain the BOM at the # beginning of it. if self.pos == 1: line = self._check_for_bom(line) self.line_pos += 1 self.buf.append(line) return line