def maybe_infer_tz(tz, inferred_tz):
if tz is None:<EOL><INDENT>tz = inferred_tz<EOL><DEDENT>elif inferred_tz is None:<EOL><INDENT>pass<EOL><DEDENT>elif not timezones.tz_compare(tz, inferred_tz):<EOL><INDENT>raise TypeError('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>.format(inferred_tz=inferred_tz, tz=tz))<EOL><DEDENT>return tz<EOL>
If a timezone is inferred from data, check that it is compatible with
the user-provided timezone, if any.

Parameters
----------
tz : tzinfo or None
inferred_tz : tzinfo or None

Returns
-------
tz : tzinfo or None

Raises
------
TypeError : if both timezones are present but do not match