def validate_dtype_freq(dtype, freq):
if freq is not None:<EOL><INDENT>freq = frequencies.to_offset(freq)<EOL><DEDENT>if dtype is not None:<EOL><INDENT>dtype = pandas_dtype(dtype)<EOL>if not is_period_dtype(dtype):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if freq is None:<EOL><INDENT>freq = dtype.freq<EOL><DEDENT>elif freq != dtype.freq:<EOL><INDENT>raise IncompatibleFrequency('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>return freq<EOL>
If both a dtype and a freq are available, ensure they match.  If only
dtype is available, extract the implied freq.

Parameters
----------
dtype : dtype
freq : DateOffset or None

Returns
-------
freq : DateOffset

Raises
------
ValueError : non-period dtype
IncompatibleFrequency : mismatch between dtype and freq