def _merge_adjacent_rows(self, rows):
ret = list()<EOL>prev_row = None<EOL>for row in rows:<EOL><INDENT>if prev_row:<EOL><INDENT>relation = Allen.relation(prev_row[self._key_start_date],<EOL>prev_row[self._key_end_date],<EOL>row[self._key_start_date],<EOL>row[self._key_end_date])<EOL>if relation is None:<EOL><INDENT>return []<EOL><DEDENT>elif relation == Allen.X_BEFORE_Y:<EOL><INDENT>ret.append(prev_row)<EOL>prev_row = row<EOL><DEDENT>elif relation == Allen.X_MEETS_Y:<EOL><INDENT>if self._equal(prev_row, row):<EOL><INDENT>prev_row[self._key_end_date] = row[self._key_end_date]<EOL><DEDENT>else:<EOL><INDENT>ret.append(prev_row)<EOL>prev_row = row<EOL><DEDENT><DEDENT>elif relation == Allen.X_OVERLAPS_WITH_Y:<EOL><INDENT>if self._equal(prev_row, row):<EOL><INDENT>prev_row[self._key_end_date] = row[self._key_end_date]<EOL><DEDENT>else:<EOL><INDENT>prev_row[self._key_end_date] = row[self._key_start_date] - <NUM_LIT:1><EOL>ret.append(prev_row)<EOL>prev_row = row<EOL><DEDENT><DEDENT>elif relation == Allen.X_STARTS_Y:<EOL><INDENT>prev_row = row<EOL><DEDENT>elif relation == Allen.X_EQUAL_Y:<EOL><INDENT>prev_row = row<EOL><DEDENT>elif relation == Allen.X_DURING_Y_INVERSE:<EOL><INDENT>if self._equal(prev_row, row):<EOL><INDENT>prev_row[self._key_end_date] = row[self._key_end_date]<EOL><DEDENT>else:<EOL><INDENT>prev_row[self._key_end_date] = row[self._key_start_date] - <NUM_LIT:1><EOL>ret.append(prev_row)<EOL>prev_row = row<EOL><DEDENT><DEDENT>elif relation == Allen.X_FINISHES_Y_INVERSE:<EOL><INDENT>if not self._equal(prev_row, row):<EOL><INDENT>prev_row[self._key_end_date] = row[self._key_start_date] - <NUM_LIT:1><EOL>ret.append(prev_row)<EOL>prev_row = row<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>'.format(relation))<EOL><DEDENT><DEDENT>elif row[self._key_start_date] <= row[self._key_end_date]:<EOL><INDENT>prev_row = row<EOL><DEDENT><DEDENT>if prev_row:<EOL><INDENT>ret.append(prev_row)<EOL><DEDENT>return ret<EOL>
Resolves adjacent and overlapping rows. Overlapping rows are resolved as follows:
* The interval with the most recent begin date prevails for the overlapping period.
* If the begin dates are the same the interval with the most recent end date prevails.
* If the begin and end dates are equal the last row in the data set prevails.
Identical (excluding begin and end date) adjacent rows are replace with a single row.

:param list[dict[str,T]] rows: The rows in a group (i.e. with the same natural key).
.
:rtype: list[dict[str,T]]