def _check_ndim(self, values, ndim):
if ndim is None:<EOL><INDENT>ndim = values.ndim<EOL><DEDENT>if self._validate_ndim and values.ndim != ndim:<EOL><INDENT>msg = ("<STR_LIT>"<EOL>"<STR_LIT>")<EOL>raise ValueError(msg.format(values.ndim, ndim))<EOL><DEDENT>return ndim<EOL>
ndim inference and validation.

Infers ndim from 'values' if not provided to __init__.
Validates that values.ndim and ndim are consistent if and only if
the class variable '_validate_ndim' is True.

Parameters
----------
values : array-like
ndim : int or None

Returns
-------
ndim : int

Raises
------
ValueError : the number of dimensions do not match