def checkpoint(self, checkpointSink, maxRows):
checkpointSink.truncate()<EOL>if self.__dataset is None:<EOL><INDENT>if self.__checkpointCache is not None:<EOL><INDENT>self.__checkpointCache.seek(<NUM_LIT:0>)<EOL>shutil.copyfileobj(self.__checkpointCache, checkpointSink)<EOL>checkpointSink.flush()<EOL>return<EOL><DEDENT>else:<EOL><INDENT>return<EOL><DEDENT><DEDENT>self.__dataset.flush()<EOL>totalDataRows = self.__dataset.getDataRowCount()<EOL>if totalDataRows == <NUM_LIT:0>:<EOL><INDENT>return<EOL><DEDENT>reader = FileRecordStream(self.__datasetPath, missingValues=[])<EOL>writer = csv.writer(checkpointSink)<EOL>writer.writerow(reader.getFieldNames())<EOL>numToWrite = min(maxRows, totalDataRows)<EOL>numRowsToSkip = totalDataRows - numToWrite<EOL>for i in range(numRowsToSkip):<EOL><INDENT>next(reader)<EOL><DEDENT>numWritten = <NUM_LIT:0><EOL>while True:<EOL><INDENT>row = reader.getNextRecord()<EOL>if row is None:<EOL><INDENT>break;<EOL><DEDENT>row =  [str(element) for element in row]<EOL>writer.writerow(row)<EOL>numWritten +=<NUM_LIT:1><EOL><DEDENT>assert numWritten == numToWrite,"<STR_LIT>" % (numWritten, numToWrite)<EOL>checkpointSink.flush()<EOL>return<EOL>
[virtual method override] Save a checkpoint of the prediction output
        stream. The checkpoint comprises up to maxRows of the most recent inference
        records.

        Parameters:
        ----------------------------------------------------------------------
        checkpointSink:     A File-like object where predictions checkpoint data, if
                            any, will be stored.
        maxRows:            Maximum number of most recent inference rows
                            to checkpoint.