def dt64arr_to_periodarr(data, freq, tz=None):
if data.dtype != np.dtype('<STR_LIT>'):<EOL><INDENT>raise ValueError('<STR_LIT>'.format(dtype=data.dtype))<EOL><DEDENT>if freq is None:<EOL><INDENT>if isinstance(data, ABCIndexClass):<EOL><INDENT>data, freq = data._values, data.freq<EOL><DEDENT>elif isinstance(data, ABCSeries):<EOL><INDENT>data, freq = data._values, data.dt.freq<EOL><DEDENT><DEDENT>freq = Period._maybe_convert_freq(freq)<EOL>if isinstance(data, (ABCIndexClass, ABCSeries)):<EOL><INDENT>data = data._values<EOL><DEDENT>base, mult = libfrequencies.get_freq_code(freq)<EOL>return libperiod.dt64arr_to_periodarr(data.view('<STR_LIT>'), base, tz), freq<EOL>
Convert an datetime-like array to values Period ordinals.

Parameters
----------
data : Union[Series[datetime64[ns]], DatetimeIndex, ndarray[datetime64ns]]
freq : Optional[Union[str, Tick]]
    Must match the `freq` on the `data` if `data` is a DatetimeIndex
    or Series.
tz : Optional[tzinfo]

Returns
-------
ordinals : ndarray[int]
freq : Tick
    The frequencey extracted from the Series or DatetimeIndex if that's
    used.