예제 #1
0
 def read_truncated_csv(start, stop):
     return pd.read_csv(io._TruncatingFileHandle(
         BytesIO(contents.encode('ascii')),
         restriction_trackers.OffsetRestrictionTracker(
             restriction_trackers.OffsetRange(start, stop)),
         splitter=io._CsvSplitter((), kwargs, read_chunk_size=7)),
                        index_col=0,
                        **kwargs)
예제 #2
0
파일: io_test.py 프로젝트: zhoufek/beam
 def _run_truncating_file_handle_iter_test(self,
                                           s,
                                           delim=' ',
                                           chunk_size=10):
     tracker = restriction_trackers.OffsetRestrictionTracker(
         restriction_trackers.OffsetRange(0, len(s)))
     handle = io._TruncatingFileHandle(StringIO(s),
                                       tracker,
                                       splitter=io._DelimSplitter(
                                           delim, chunk_size))
     self.assertEqual(s, ''.join(list(handle)))
예제 #3
0
 def _run_truncating_file_handle_test(
     self, s, splits, delim=' ', chunk_size=10):
   split_results = []
   next_range = restriction_trackers.OffsetRange(0, len(s))
   for split in list(splits) + [None]:
     tracker = restriction_trackers.OffsetRestrictionTracker(next_range)
     handle = io._TruncatingFileHandle(
         StringIO(s), tracker, splitter=io._DelimSplitter(delim, chunk_size))
     data = ''
     chunk = handle.read(1)
     if split is not None:
       _, next_range = tracker.try_split(split)
     while chunk:
       data += chunk
       chunk = handle.read(7)
     split_results.append(data)
   return split_results
예제 #4
0
 def create_tracker(self, restriction):
   return restriction_trackers.OffsetRestrictionTracker(restriction)