Repository: sktime/sktime

Issue:
[BUG] Failing tests with pandas version 1.4.0
**Describe the bug**
<!--
A clear and concise description of what the bug is.
-->

With the most recent version of pandas 1.4.0 two test are failing

```
FAILED alignment/tests/test_all_aligners.py::test_get_alignment_loc[AlignerDTWfromDist]
FAILED alignment/tests/test_all_aligners.py::test_get_alignment_loc[AlignerDTW]
```

**To Reproduce**
<!--
Add a Minimal, Complete, and Verifiable example (for more details, see e.g. https://stackoverflow.com/help/mcve

If the code is too long, feel free to put it in a public gist and link it in the issue: https://gist.github.com
-->

Bump your pandas version to 1.4.0

```bash
pip install -U pandas==1.4.0
pytest sktime/alignment/tests/test_all_aligners.py
```

**Expected behavior**
<!--
A clear and concise description of what you expected to happen.
-->
Test are passing.

**Additional context**
<!--
Add any other context about the problem here.
-->



<details>
<summary>Traceback</summary>


```python
__________________ test_get_alignment_loc[AlignerDTWfromDist] __________________
[gw1] linux -- Python 3.8.12 /opt/hostedtoolcache/Python/3.8.12/x64/bin/python

Aligner = <class 'sktime.alignment.dtw_python.AlignerDTWfromDist'>

    @pytest.mark.parametrize("Aligner", ALIGNERS)
    def test_get_alignment_loc(Aligner):
        """Test that get_alignment returns an alignment (loc)."""
        f = Aligner.create_test_instance()
    
        X = [_make_series(n_columns=2), _make_series(n_columns=2)]
>       align = f.fit(X).get_alignment_loc()

Aligner    = <class 'sktime.alignment.dtw_python.AlignerDTWfromDist'>
X          = [                   0         1
2000-01-01  1.877993  4.022627
2000-01-02  2.892609  2.980591
2000-01-03  3.634473  3....02-16  2.888466  5.365541
2000-02-17  2.020916  5.176993
2000-02-18  2.891862  5.164779
2000-02-19  2.884114  4.572237]
f          = AlignerDTWfromDist(dist_trafo=ScipyDist(colalign='intersect',
                                        metric='euclidea...
                   open_begin=False, open_end=False, step_pattern='symmetric2',
                   window_type='none')

/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/sktime/alignment/tests/test_all_aligners.py:37: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/sktime/alignment/base.py:152: in get_alignment_loc
    return self._get_alignment_loc()
        self       = AlignerDTWfromDist(dist_trafo=ScipyDist(colalign='intersect',
                                        metric='euclidea...
                   open_begin=False, open_end=False, step_pattern='symmetric2',
                   window_type='none')
/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/sktime/alignment/base.py:180: in _get_alignment_loc
    return convert_align_to_align_loc(align, X)
        X          = [                   0         1
2000-01-01  1.877993  4.022627
2000-01-02  2.892609  2.980591
2000-01-03  3.634473  3....02-16  2.888466  5.365541
2000-02-17  2.020916  5.176993
2000-02-18  2.891862  5.164779
2000-02-19  2.884114  4.572237]
        align      =     ind0  ind1
0      0     0
1      1     0
2      2     1
3      3     1
4      4     1
..   ...   ...
91    45    49
92    46    49
93    47    49
94    48    49
95    49    49

[96 rows x 2 columns]
        self       = AlignerDTWfromDist(dist_trafo=ScipyDist(colalign='intersect',
                                        metric='euclidea...
                   open_begin=False, open_end=False, step_pattern='symmetric2',
                   window_type='none')
/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/sktime/alignment/utils/utils_align.py:94: in convert_align_to_align_loc
    loc_series = pd.Series(Xi.index, dtype="Int64").reindex(align[indi], copy=copy)
        X          = [                   0         1
2000-01-01  1.877993  4.022627
2000-01-02  2.892609  2.980591
2000-01-03  3.634473  3....02-16  2.888466  5.365541
2000-02-17  2.020916  5.176993
2000-02-18  2.891862  5.164779
2000-02-19  2.884114  4.572237]
        Xi         =                    0         1
2000-01-01  1.877993  4.022627
2000-01-02  2.892609  2.980591
2000-01-03  3.634473  3.0...-02-16  2.473775  2.820853
2000-02-17  4.575492  2.810851
2000-02-18  2.312191  3.239057
2000-02-19  4.142755  3.344174
        align      =     ind0  ind1
0      0     0
1      1     0
2      2     1
3      3     1
4      4     1
..   ...   ...
91    45    49
92    46    49
93    47    49
94    48    49
95    49    49

[96 rows x 2 columns]
        align_name = 'align'
        copy       = True
        df_name    = 'X'
        i          = 0
        indi       = 'ind0'
/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/pandas/core/series.py:396: in __init__
    data = data.astype(dtype)
        copy       = False
        data       = DatetimeIndex(['2000-01-01', '2000-01-02', '2000-01-03', '2000-01-04',
               '2000-01-05', '2000-01-06', '200...'2000-02-16', '2000-02-17',
               '2000-02-18', '2000-02-19'],
              dtype='datetime64[ns]', freq='D')
        dtype      = Int64Dtype()
        fastpath   = False
        index      = None
        name       = None
        self       = <[AttributeError("'Series' object has no attribute '_mgr'") raised in repr()] Series object at 0x7f3cf6e1ee50>
/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/pandas/core/indexes/base.py:1049: in astype
    new_values = values.astype(dtype, copy=copy)
        copy       = True
        dtype      = Int64Dtype()
        self       = DatetimeIndex(['2000-01-01', '2000-01-02', '2000-01-03', '2000-01-04',
               '2000-01-05', '2000-01-06', '200...'2000-02-16', '2000-02-17',
               '2000-02-18', '2000-02-19'],
              dtype='datetime64[ns]', freq='D')
        values     = <DatetimeArray>
['2000-01-01 00:00:00', '2000-01-02 00:00:00', '2000-01-03 00:00:00',
 '2000-01-04 00:00:00', '2000-01...2-16 00:00:00', '2000-02-17 00:00:00',
 '2000-02-18 00:00:00', '2000-02-19 00:00:00']
Length: 50, dtype: datetime64[ns]
/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/pandas/core/arrays/datetimes.py:666: in astype
    return dtl.DatetimeLikeArrayMixin.astype(self, dtype, copy)
        copy       = True
        dtype      = Int64Dtype()
        self       = <DatetimeArray>
['2000-01-01 00:00:00', '2000-01-02 00:00:00', '2000-01-03 00:00:00',
 '2000-01-04 00:00:00', '2000-01...2-16 00:00:00', '2000-02-17 00:00:00',
 '2000-02-18 00:00:00', '2000-02-19 00:00:00']
Length: 50, dtype: datetime64[ns]
/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/pandas/core/arrays/datetimelike.py:427: in astype
    return super().astype(dtype, copy=copy)
        __class__  = <class 'pandas.core.arrays.datetimelike.DatetimeLikeArrayMixin'>
        copy       = True
        dtype      = Int64Dtype()
        self       = <DatetimeArray>
['2000-01-01 00:00:00', '2000-01-02 00:00:00', '2000-01-03 00:00:00',
 '2000-01-04 00:00:00', '2000-01...2-16 00:00:00', '2000-02-17 00:00:00',
 '2000-02-18 00:00:00', '2000-02-19 00:00:00']
Length: 50, dtype: datetime64[ns]
/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/pandas/core/arrays/base.py:582: in astype
    return cls._from_sequence(self, dtype=dtype, copy=copy)
        cls        = <class 'pandas.core.arrays.integer.IntegerArray'>
        copy       = True
        dtype      = Int64Dtype()
        self       = <DatetimeArray>
['2000-01-01 00:00:00', '2000-01-02 00:00:00', '2000-01-03 00:00:00',
 '2000-01-04 00:00:00', '2000-01...2-16 00:00:00', '2000-02-17 00:00:00',
 '2000-02-18 00:00:00', '2000-02-19 00:00:00']
Length: 50, dtype: datetime64[ns]
/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/pandas/core/arrays/integer.py:325: in _from_sequence
    values, mask = coerce_to_array(scalars, dtype=dtype, copy=copy)
        cls        = <class 'pandas.core.arrays.integer.IntegerArray'>
        copy       = True
        dtype      = Int64Dtype()
        scalars    = <DatetimeArray>
['2000-01-01 00:00:00', '2000-01-02 00:00:00', '2000-01-03 00:00:00',
 '2000-01-04 00:00:00', '2000-01...2-16 00:00:00', '2000-02-17 00:00:00',
 '2000-02-18 00:00:00', '2000-02-19 00:00:00']
Length: 50, dtype: datetime64[ns]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

values = array(['2000-01-01T00:00:00.000000000', '2000-01-02T00:00:00.000000000',
       '2000-01-03T00:00:00.000000000', '2000...:00.000000000',
       '2000-02-18T00:00:00.000000000', '2000-02-19T00:00:00.000000000'],
      dtype='datetime64[ns]')
dtype = Int64Dtype(), mask = None, copy = True

    def coerce_to_array(
        values, dtype, mask=None, copy: bool = False
    ) -> tuple[np.ndarray, np.ndarray]:
        """
        Coerce the input values array to numpy arrays with a mask.
    
        Parameters
        ----------
        values : 1D list-like
        dtype : integer dtype
        mask : bool 1D array, optional
        copy : bool, default False
            if True, copy the input
    
        Returns
        -------
        tuple of (values, mask)
        """
        # if values is integer numpy array, preserve its dtype
        if dtype is None and hasattr(values, "dtype"):
            if is_integer_dtype(values.dtype):
                dtype = values.dtype
    
        if dtype is not None:
            if isinstance(dtype, str) and (
                dtype.startswith("Int") or dtype.startswith("UInt")
            ):
                # Avoid DeprecationWarning from NumPy about np.dtype("Int64")
                # https://github.com/numpy/numpy/pull/7476
                dtype = dtype.lower()
    
            if not issubclass(type(dtype), _IntegerDtype):
                try:
                    dtype = INT_STR_TO_DTYPE[str(np.dtype(dtype))]
                except KeyError as err:
                    raise ValueError(f"invalid dtype specified {dtype}") from err
    
        if isinstance(values, IntegerArray):
            values, mask = values._data, values._mask
            if dtype is not None:
                values = values.astype(dtype.numpy_dtype, copy=False)
    
            if copy:
                values = values.copy()
                mask = mask.copy()
            return values, mask
    
        values = np.array(values, copy=copy)
        inferred_type = None
        if is_object_dtype(values.dtype) or is_string_dtype(values.dtype):
            inferred_type = lib.infer_dtype(values, skipna=True)
            if inferred_type == "empty":
                pass
            elif inferred_type not in [
                "floating",
                "integer",
                "mixed-integer",
                "integer-na",
                "mixed-integer-float",
                "string",
                "unicode",
            ]:
                raise TypeError(f"{values.dtype} cannot be converted to an IntegerDtype")
    
        elif is_bool_dtype(values) and is_integer_dtype(dtype):
            values = np.array(values, dtype=int, copy=copy)
    
        elif not (is_integer_dtype(values) or is_float_dtype(values)):
>           raise TypeError(f"{values.dtype} cannot be converted to an IntegerDtype")
E           TypeError: datetime64[ns] cannot be converted to an IntegerDtype

copy       = True
dtype      = Int64Dtype()
inferred_type = None
mask       = None
values     = array(['2000-01-01T00:00:00.000000000', '2000-01-02T00:00:00.000000000',
       '2000-01-03T00:00:00.000000000', '2000...:00.000000000',
       '2000-02-18T00:00:00.000000000', '2000-02-19T00:00:00.000000000'],
      dtype='datetime64[ns]')
```

</details>





**Versions**
<details>

<!--
Please run the following code snippet and paste the output here:
 
from sktime import show_versions; show_versions()
-->

</details>

<!-- Thanks for contributing! -->



Discussion:

Resolving patch:
diff --git a/sktime/alignment/utils/utils_align.py b/sktime/alignment/utils/utils_align.py
--- a/sktime/alignment/utils/utils_align.py
+++ b/sktime/alignment/utils/utils_align.py
@@ -66,9 +66,9 @@ def convert_align_to_align_loc(align, X, align_name="align", df_name="X", copy=T
 
     convert_align_to_align_loc(align_df, X)
     """
-    # todo: need to wait for datatypes PR to merge
-    # from sktime.datatypes import check_is_mtype
-    # check_is_mtype(align, "align-frame", var_name=df_name)
+    from sktime.datatypes import check_is_mtype
+
+    check_is_mtype(align, "alignment", scitype="Alignment", var_name=align_name)
 
     if not isinstance(X, list):
         raise ValueError(f"{df_name} must be a list of pandas.DataFrame")
@@ -91,7 +91,7 @@ def convert_align_to_align_loc(align, X, align_name="align", df_name="X", copy=T
 
         # reindex X to the alignment positions
         #  this also deals with np.nan indices
-        loc_series = pd.Series(Xi.index, dtype="Int64").reindex(align[indi], copy=copy)
+        loc_series = pd.Series(Xi.index).reindex(align[indi], copy=copy)
         align[indi] = loc_series.values
 
     return align


Test patch: