We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[BUG] ValueError when fitting Prophet and X.index.name=='ds' 
**Describe the bug**
The following error is raised when trying to fit Prophet using X where the name of X's DateTimeIndex is named "ds":
ValueError: 'ds' is both an index level and a column label, which is ambiguous.

It happens in the _merge_X method in the _ProphetAdapter, line 193, because after running line 191, X contains a column and an index called "ds".

A suggested solution would be to add this oneliner before line 189 of .forecasting.base.adapters._fbprophet.py:
```python
X.index.name = "index"
```
Note: This assumes that X never has a MultiIndex. Not sure if that ever happens though..

This way, the user is still allowed to call X's index "ds". Since "ds" is the standard name that Prophet users use for their DateTime column, this is the most intuitive and least restrictive solution.

**To Reproduce**
```python
import pandas as pd
from sktime.datasets import load_airline
from sktime.forecasting.fbprophet import Prophet
from sktime.forecasting.model_selection import ForecastingGridSearchCV
from sktime.forecasting.model_selection import ExpandingWindowSplitter

y_train = load_airline().to_timestamp(freq='M')

# Commenting out the following line makes everything run smoothly
y_train.index.name = 'ds'

X_train = pd.DataFrame({'x1':y_train+200, 'x2':y_train+100})

forecaster = Prophet(yearly_seasonality=False, weekly_seasonality=False, daily_seasonality=False)
forecaster.fit(y_train, X_train)
```

**Expected behavior**
No error

**Additional context**


**Versions**
<details>

System:
    python: 3.9.7 | packaged by conda-forge | (default, Sep 23 2021, 07:24:41) [MSC v.1916 64 bit (AMD64)]
executable: C:\Users\............\env\python.exe
   machine: Windows-10-10.0.19043-SP0

Python dependencies:
          pip: 21.2.4
   setuptools: 58.1.0
      sklearn: 1.0
       sktime: 0.7.0
  statsmodels: 0.12.2
        numpy: 1.21.2
        scipy: 1.7.1
       Cython: 0.29.24
       pandas: 1.3.3
   matplotlib: 3.4.3
       joblib: 1.0.1
        numba: 0.53.1
     pmdarima: 1.8.3
      tsfresh: None
</details>


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `sktime/utils/validation/series.py`
Content:
```
1 #!/usr/bin/env python3 -u
2 # -*- coding: utf-8 -*-
3 
4 """Functions for checking input data."""
5 
6 __author__ = ["Markus Löning", "Drishti Bhasin"]
7 __all__ = [
8     "check_series",
9     "check_time_index",
10     "check_equal_time_index",
11     "check_consistent_index_type",
12 ]
13 import pandas as pd
14 import numpy as np
15 
16 # We currently support the following types for input data and time index types.
17 VALID_DATA_TYPES = (pd.DataFrame, pd.Series, np.ndarray)
18 VALID_INDEX_TYPES = (pd.Int64Index, pd.RangeIndex, pd.PeriodIndex, pd.DatetimeIndex)
19 
20 
21 def _check_is_univariate(y, var_name="input"):
22     """Check if series is univariate."""
23     if isinstance(y, pd.DataFrame):
24         nvars = y.shape[1]
25         if nvars > 1:
26             raise ValueError(
27                 f"{var_name} must be univariate, but found {nvars} variables."
28             )
29     if isinstance(y, np.ndarray) and y.ndim > 1 and y.shape[1] > 1:
30         raise ValueError(
31             f"{var_name} must be univariate, but found np.ndarray with more than "
32             "one column"
33         )
34 
35 
36 def _check_is_multivariate(Z, var_name="input"):
37     """Check if series is multivariate."""
38     if isinstance(Z, pd.Series):
39         raise ValueError(f"{var_name} must have 2 or more variables, but found 1.")
40     if isinstance(Z, pd.DataFrame):
41         nvars = Z.shape[1]
42         if nvars < 2:
43             raise ValueError(
44                 f"{var_name} must have 2 or more variables, but found {nvars}."
45             )
46     if isinstance(Z, np.ndarray):
47         if Z.ndim == 1 or (Z.ndim == 2 and Z.shape[1] == 1):
48             raise ValueError(f"{var_name} must have 2 or more variables, but found 1.")
49 
50 
51 def check_series(
52     Z,
53     enforce_univariate=False,
54     enforce_multivariate=False,
55     allow_empty=False,
56     allow_numpy=True,
57     allow_None=True,
58     enforce_index_type=None,
59     var_name="input",
60 ):
61     """Validate input data to be a valid mtype for Series.
62 
63     Parameters
64     ----------
65     Z : pd.Series, pd.DataFrame, np.ndarray, or None
66         Univariate or multivariate time series.
67     enforce_univariate : bool, default = False
68         If True, multivariate Z will raise an error.
69     enforce_multivariate: bool, default = False
70         If True, univariate Z will raise an error.
71     allow_empty : bool, default = False
72         whether a container with zero samples is allowed
73     allow_numpy : bool, default = True
74         whether no error is raised if Z is in a valid numpy.ndarray format
75     allow_None : bool, default = True
76         whether no error is raised if Z is None
77     enforce_index_type : type, default = None
78         type of time index
79     var_name : str, default = "input" - variable name printed in error messages
80 
81     Returns
82     -------
83     Z : pd.Series, pd.DataFrame, np.ndarray, or None
84         Validated time series - a reference to the input Z
85 
86     Raises
87     ------
88     TypeError - if Z is not in a valid type or format for scitype Series
89     if enforce_univariate is True:
90         ValueError if Z has 2 or more columns
91     if enforce_multivariate is True:
92         ValueError if Z has 1 column
93     if allow_numpy is false:
94         TypeError - if Z is of type np.ndarray
95     if allow_empty is false:
96         ValueError - if Z has length 0
97     if allow_None is false:
98         ValueError - if Z is None
99     if enforce_index_type is not None and Z is pandas type:
100         ValueError - if Z has index type other than enforce_index_type
101     """
102     if Z is None:
103         if allow_None:
104             return Z
105         else:
106             raise ValueError(var_name + " cannot be None")
107 
108     # Check if pandas series or numpy array
109     if not allow_numpy:
110         valid_data_types = tuple(
111             filter(lambda x: x is not np.ndarray, VALID_DATA_TYPES)
112         )
113     else:
114         valid_data_types = VALID_DATA_TYPES
115 
116     if not isinstance(Z, valid_data_types):
117         raise TypeError(
118             f"{var_name} must be a one of {valid_data_types}, but found type: {type(Z)}"
119         )
120 
121     if enforce_univariate and enforce_multivariate:
122         raise ValueError(
123             "`enforce_univariate` and `enforce_multivariate` cannot both be set to "
124             "True."
125         )
126 
127     if enforce_univariate:
128         _check_is_univariate(Z, var_name=var_name)
129 
130     if enforce_multivariate:
131         _check_is_multivariate(Z, var_name=var_name)
132 
133     # check time index if input data is not an NumPy ndarray
134     if not isinstance(Z, np.ndarray):
135         check_time_index(
136             Z.index,
137             allow_empty=allow_empty,
138             enforce_index_type=enforce_index_type,
139             var_name=var_name,
140         )
141 
142     return Z
143 
144 
145 def check_time_index(
146     index, allow_empty=False, enforce_index_type=None, var_name="input"
147 ):
148     """Check time index.
149 
150     Parameters
151     ----------
152     index : pd.Index or np.array
153         Time index
154     allow_empty : bool, optional (default=False)
155         If False, empty `index` raises an error.
156     enforce_index_type : type, optional (default=None)
157         type of time index
158     var_name : str, default = "input" - variable name printed in error messages
159 
160     Returns
161     -------
162     time_index : pd.Index
163         Validated time index - a reference to the input index
164     """
165     if isinstance(index, np.ndarray):
166         index = pd.Index(index)
167 
168     # We here check for type equality because isinstance does not
169     # work reliably because index types inherit from each other.
170     if not type(index) in VALID_INDEX_TYPES:
171         raise NotImplementedError(
172             f"{type(index)} is not supported for {var_name}, use "
173             f"one of {VALID_INDEX_TYPES} instead."
174         )
175 
176     if enforce_index_type and type(index) is not enforce_index_type:
177         raise NotImplementedError(
178             f"{type(index)} is not supported for {var_name}, use "
179             f"type: {enforce_index_type} instead."
180         )
181 
182     # Check time index is ordered in time
183     if not index.is_monotonic:
184         raise ValueError(
185             f"The (time) index of {var_name} must be sorted monotonically increasing, "
186             f"but found: {index}"
187         )
188 
189     # Check that index is not empty
190     if not allow_empty and len(index) < 1:
191         raise ValueError(
192             f"{var_name} must contain at least some values, but found none."
193         )
194 
195     return index
196 
197 
198 def check_equal_time_index(*ys):
199     """Check that time series have the same (time) indices.
200 
201     Parameters
202     ----------
203     *ys : tuple of pd.Series, pd.DataFrame or np.ndarray, or None
204         One or more time series
205 
206     Raises
207     ------
208     ValueError
209         If there are at least two no=-None entries of ys
210             of which pandas indices are not the same
211             np.ndarray are considered having integer range index on axis 0
212     """
213     # None entries are ignored
214     y_not_None = [y for y in ys if y is not None]
215 
216     # if there is no or just one element, there is nothing to compare
217     if len(y_not_None) < 2:
218         return None
219 
220     # only validate indices if data is passed as pd.Series
221     if isinstance(y_not_None[0], np.ndarray):
222         first_index = pd.Index(range(len(y_not_None[0])))
223     else:
224         first_index = y_not_None[0].index
225 
226     check_time_index(first_index)
227 
228     for y in y_not_None[1:]:
229         if isinstance(y, np.ndarray):
230             y_index = pd.Index(y)
231         else:
232             y_index = y.index
233 
234         check_time_index(y_index)
235 
236         if not first_index.equals(y_index):
237             raise ValueError("Some (time) indices are not the same.")
238 
239 
240 def _is_int_index(index):
241     """Check if index type is one of pd.RangeIndex or pd.Int64Index."""
242     return type(index) in (pd.Int64Index, pd.RangeIndex)
243 
244 
245 def check_consistent_index_type(a, b):
246     """Check that two indices have consistent types.
247 
248     Parameters
249     ----------
250     a : pd.Index
251         Index being checked for consistency
252     b : pd.Index
253         Index being checked for consistency
254 
255     Raises
256     ------
257     TypeError
258         If index types are inconsistent
259     """
260     msg = (
261         "Found series with inconsistent index types, please make sure all "
262         "series have the same index type."
263     )
264 
265     if _is_int_index(a):
266         if not _is_int_index(b):
267             raise TypeError(msg)
268 
269     else:
270         # check types, note that isinstance() does not work here because index
271         # types inherit from each other, hence we check for type equality
272         if not type(a) is type(b):  # noqa
273             raise TypeError(msg)
274
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/sktime/utils/validation/series.py b/sktime/utils/validation/series.py
--- a/sktime/utils/validation/series.py
+++ b/sktime/utils/validation/series.py
@@ -10,8 +10,8 @@
     "check_equal_time_index",
     "check_consistent_index_type",
 ]
-import pandas as pd
 import numpy as np
+import pandas as pd
 
 # We currently support the following types for input data and time index types.
 VALID_DATA_TYPES = (pd.DataFrame, pd.Series, np.ndarray)
@@ -56,6 +56,7 @@
     allow_numpy=True,
     allow_None=True,
     enforce_index_type=None,
+    allow_index_names=False,
     var_name="input",
 ):
     """Validate input data to be a valid mtype for Series.
@@ -76,6 +77,8 @@
         whether no error is raised if Z is None
     enforce_index_type : type, default = None
         type of time index
+    allow_index_names : bool, default = False
+        If False, names of Z.index will be set to None
     var_name : str, default = "input" - variable name printed in error messages
 
     Returns
@@ -139,6 +142,9 @@
             var_name=var_name,
         )
 
+    if not allow_index_names and not isinstance(Z, np.ndarray):
+        Z.index.names = [None for name in Z.index.names]
+
     return Z

{"golden_diff": "diff --git a/sktime/utils/validation/series.py b/sktime/utils/validation/series.py\n--- a/sktime/utils/validation/series.py\n+++ b/sktime/utils/validation/series.py\n@@ -10,8 +10,8 @@\n     \"check_equal_time_index\",\n     \"check_consistent_index_type\",\n ]\n-import pandas as pd\n import numpy as np\n+import pandas as pd\n \n # We currently support the following types for input data and time index types.\n VALID_DATA_TYPES = (pd.DataFrame, pd.Series, np.ndarray)\n@@ -56,6 +56,7 @@\n     allow_numpy=True,\n     allow_None=True,\n     enforce_index_type=None,\n+    allow_index_names=False,\n     var_name=\"input\",\n ):\n     \"\"\"Validate input data to be a valid mtype for Series.\n@@ -76,6 +77,8 @@\n         whether no error is raised if Z is None\n     enforce_index_type : type, default = None\n         type of time index\n+    allow_index_names : bool, default = False\n+        If False, names of Z.index will be set to None\n     var_name : str, default = \"input\" - variable name printed in error messages\n \n     Returns\n@@ -139,6 +142,9 @@\n             var_name=var_name,\n         )\n \n+    if not allow_index_names and not isinstance(Z, np.ndarray):\n+        Z.index.names = [None for name in Z.index.names]\n+\n     return Z\n", "issue": "[BUG] ValueError when fitting Prophet and X.index.name=='ds' \n**Describe the bug**\r\nThe following error is raised when trying to fit Prophet using X where the name of X's DateTimeIndex is named \"ds\":\r\nValueError: 'ds' is both an index level and a column label, which is ambiguous.\r\n\r\nIt happens in the _merge_X method in the _ProphetAdapter, line 193, because after running line 191, X contains a column and an index called \"ds\".\r\n\r\nA suggested solution would be to add this oneliner before line 189 of .forecasting.base.adapters._fbprophet.py:\r\n```python\r\nX.index.name = \"index\"\r\n```\r\nNote: This assumes that X never has a MultiIndex. Not sure if that ever happens though..\r\n\r\nThis way, the user is still allowed to call X's index \"ds\". Since \"ds\" is the standard name that Prophet users use for their DateTime column, this is the most intuitive and least restrictive solution.\r\n\r\n**To Reproduce**\r\n```python\r\nimport pandas as pd\r\nfrom sktime.datasets import load_airline\r\nfrom sktime.forecasting.fbprophet import Prophet\r\nfrom sktime.forecasting.model_selection import ForecastingGridSearchCV\r\nfrom sktime.forecasting.model_selection import ExpandingWindowSplitter\r\n\r\ny_train = load_airline().to_timestamp(freq='M')\r\n\r\n# Commenting out the following line makes everything run smoothly\r\ny_train.index.name = 'ds'\r\n\r\nX_train = pd.DataFrame({'x1':y_train+200, 'x2':y_train+100})\r\n\r\nforecaster = Prophet(yearly_seasonality=False, weekly_seasonality=False, daily_seasonality=False)\r\nforecaster.fit(y_train, X_train)\r\n```\r\n\r\n**Expected behavior**\r\nNo error\r\n\r\n**Additional context**\r\n\r\n\r\n**Versions**\r\n<details>\r\n\r\nSystem:\r\n    python: 3.9.7 | packaged by conda-forge | (default, Sep 23 2021, 07:24:41) [MSC v.1916 64 bit (AMD64)]\r\nexecutable: C:\\Users\\............\\env\\python.exe\r\n   machine: Windows-10-10.0.19043-SP0\r\n\r\nPython dependencies:\r\n          pip: 21.2.4\r\n   setuptools: 58.1.0\r\n      sklearn: 1.0\r\n       sktime: 0.7.0\r\n  statsmodels: 0.12.2\r\n        numpy: 1.21.2\r\n        scipy: 1.7.1\r\n       Cython: 0.29.24\r\n       pandas: 1.3.3\r\n   matplotlib: 3.4.3\r\n       joblib: 1.0.1\r\n        numba: 0.53.1\r\n     pmdarima: 1.8.3\r\n      tsfresh: None\r\n</details>\r\n\n", "before_files": [{"content": "#!/usr/bin/env python3 -u\n# -*- coding: utf-8 -*-\n\n\"\"\"Functions for checking input data.\"\"\"\n\n__author__ = [\"Markus L\u00f6ning\", \"Drishti Bhasin\"]\n__all__ = [\n    \"check_series\",\n    \"check_time_index\",\n    \"check_equal_time_index\",\n    \"check_consistent_index_type\",\n]\nimport pandas as pd\nimport numpy as np\n\n# We currently support the following types for input data and time index types.\nVALID_DATA_TYPES = (pd.DataFrame, pd.Series, np.ndarray)\nVALID_INDEX_TYPES = (pd.Int64Index, pd.RangeIndex, pd.PeriodIndex, pd.DatetimeIndex)\n\n\ndef _check_is_univariate(y, var_name=\"input\"):\n    \"\"\"Check if series is univariate.\"\"\"\n    if isinstance(y, pd.DataFrame):\n        nvars = y.shape[1]\n        if nvars > 1:\n            raise ValueError(\n                f\"{var_name} must be univariate, but found {nvars} variables.\"\n            )\n    if isinstance(y, np.ndarray) and y.ndim > 1 and y.shape[1] > 1:\n        raise ValueError(\n            f\"{var_name} must be univariate, but found np.ndarray with more than \"\n            \"one column\"\n        )\n\n\ndef _check_is_multivariate(Z, var_name=\"input\"):\n    \"\"\"Check if series is multivariate.\"\"\"\n    if isinstance(Z, pd.Series):\n        raise ValueError(f\"{var_name} must have 2 or more variables, but found 1.\")\n    if isinstance(Z, pd.DataFrame):\n        nvars = Z.shape[1]\n        if nvars < 2:\n            raise ValueError(\n                f\"{var_name} must have 2 or more variables, but found {nvars}.\"\n            )\n    if isinstance(Z, np.ndarray):\n        if Z.ndim == 1 or (Z.ndim == 2 and Z.shape[1] == 1):\n            raise ValueError(f\"{var_name} must have 2 or more variables, but found 1.\")\n\n\ndef check_series(\n    Z,\n    enforce_univariate=False,\n    enforce_multivariate=False,\n    allow_empty=False,\n    allow_numpy=True,\n    allow_None=True,\n    enforce_index_type=None,\n    var_name=\"input\",\n):\n    \"\"\"Validate input data to be a valid mtype for Series.\n\n    Parameters\n    ----------\n    Z : pd.Series, pd.DataFrame, np.ndarray, or None\n        Univariate or multivariate time series.\n    enforce_univariate : bool, default = False\n        If True, multivariate Z will raise an error.\n    enforce_multivariate: bool, default = False\n        If True, univariate Z will raise an error.\n    allow_empty : bool, default = False\n        whether a container with zero samples is allowed\n    allow_numpy : bool, default = True\n        whether no error is raised if Z is in a valid numpy.ndarray format\n    allow_None : bool, default = True\n        whether no error is raised if Z is None\n    enforce_index_type : type, default = None\n        type of time index\n    var_name : str, default = \"input\" - variable name printed in error messages\n\n    Returns\n    -------\n    Z : pd.Series, pd.DataFrame, np.ndarray, or None\n        Validated time series - a reference to the input Z\n\n    Raises\n    ------\n    TypeError - if Z is not in a valid type or format for scitype Series\n    if enforce_univariate is True:\n        ValueError if Z has 2 or more columns\n    if enforce_multivariate is True:\n        ValueError if Z has 1 column\n    if allow_numpy is false:\n        TypeError - if Z is of type np.ndarray\n    if allow_empty is false:\n        ValueError - if Z has length 0\n    if allow_None is false:\n        ValueError - if Z is None\n    if enforce_index_type is not None and Z is pandas type:\n        ValueError - if Z has index type other than enforce_index_type\n    \"\"\"\n    if Z is None:\n        if allow_None:\n            return Z\n        else:\n            raise ValueError(var_name + \" cannot be None\")\n\n    # Check if pandas series or numpy array\n    if not allow_numpy:\n        valid_data_types = tuple(\n            filter(lambda x: x is not np.ndarray, VALID_DATA_TYPES)\n        )\n    else:\n        valid_data_types = VALID_DATA_TYPES\n\n    if not isinstance(Z, valid_data_types):\n        raise TypeError(\n            f\"{var_name} must be a one of {valid_data_types}, but found type: {type(Z)}\"\n        )\n\n    if enforce_univariate and enforce_multivariate:\n        raise ValueError(\n            \"`enforce_univariate` and `enforce_multivariate` cannot both be set to \"\n            \"True.\"\n        )\n\n    if enforce_univariate:\n        _check_is_univariate(Z, var_name=var_name)\n\n    if enforce_multivariate:\n        _check_is_multivariate(Z, var_name=var_name)\n\n    # check time index if input data is not an NumPy ndarray\n    if not isinstance(Z, np.ndarray):\n        check_time_index(\n            Z.index,\n            allow_empty=allow_empty,\n            enforce_index_type=enforce_index_type,\n            var_name=var_name,\n        )\n\n    return Z\n\n\ndef check_time_index(\n    index, allow_empty=False, enforce_index_type=None, var_name=\"input\"\n):\n    \"\"\"Check time index.\n\n    Parameters\n    ----------\n    index : pd.Index or np.array\n        Time index\n    allow_empty : bool, optional (default=False)\n        If False, empty `index` raises an error.\n    enforce_index_type : type, optional (default=None)\n        type of time index\n    var_name : str, default = \"input\" - variable name printed in error messages\n\n    Returns\n    -------\n    time_index : pd.Index\n        Validated time index - a reference to the input index\n    \"\"\"\n    if isinstance(index, np.ndarray):\n        index = pd.Index(index)\n\n    # We here check for type equality because isinstance does not\n    # work reliably because index types inherit from each other.\n    if not type(index) in VALID_INDEX_TYPES:\n        raise NotImplementedError(\n            f\"{type(index)} is not supported for {var_name}, use \"\n            f\"one of {VALID_INDEX_TYPES} instead.\"\n        )\n\n    if enforce_index_type and type(index) is not enforce_index_type:\n        raise NotImplementedError(\n            f\"{type(index)} is not supported for {var_name}, use \"\n            f\"type: {enforce_index_type} instead.\"\n        )\n\n    # Check time index is ordered in time\n    if not index.is_monotonic:\n        raise ValueError(\n            f\"The (time) index of {var_name} must be sorted monotonically increasing, \"\n            f\"but found: {index}\"\n        )\n\n    # Check that index is not empty\n    if not allow_empty and len(index) < 1:\n        raise ValueError(\n            f\"{var_name} must contain at least some values, but found none.\"\n        )\n\n    return index\n\n\ndef check_equal_time_index(*ys):\n    \"\"\"Check that time series have the same (time) indices.\n\n    Parameters\n    ----------\n    *ys : tuple of pd.Series, pd.DataFrame or np.ndarray, or None\n        One or more time series\n\n    Raises\n    ------\n    ValueError\n        If there are at least two no=-None entries of ys\n            of which pandas indices are not the same\n            np.ndarray are considered having integer range index on axis 0\n    \"\"\"\n    # None entries are ignored\n    y_not_None = [y for y in ys if y is not None]\n\n    # if there is no or just one element, there is nothing to compare\n    if len(y_not_None) < 2:\n        return None\n\n    # only validate indices if data is passed as pd.Series\n    if isinstance(y_not_None[0], np.ndarray):\n        first_index = pd.Index(range(len(y_not_None[0])))\n    else:\n        first_index = y_not_None[0].index\n\n    check_time_index(first_index)\n\n    for y in y_not_None[1:]:\n        if isinstance(y, np.ndarray):\n            y_index = pd.Index(y)\n        else:\n            y_index = y.index\n\n        check_time_index(y_index)\n\n        if not first_index.equals(y_index):\n            raise ValueError(\"Some (time) indices are not the same.\")\n\n\ndef _is_int_index(index):\n    \"\"\"Check if index type is one of pd.RangeIndex or pd.Int64Index.\"\"\"\n    return type(index) in (pd.Int64Index, pd.RangeIndex)\n\n\ndef check_consistent_index_type(a, b):\n    \"\"\"Check that two indices have consistent types.\n\n    Parameters\n    ----------\n    a : pd.Index\n        Index being checked for consistency\n    b : pd.Index\n        Index being checked for consistency\n\n    Raises\n    ------\n    TypeError\n        If index types are inconsistent\n    \"\"\"\n    msg = (\n        \"Found series with inconsistent index types, please make sure all \"\n        \"series have the same index type.\"\n    )\n\n    if _is_int_index(a):\n        if not _is_int_index(b):\n            raise TypeError(msg)\n\n    else:\n        # check types, note that isinstance() does not work here because index\n        # types inherit from each other, hence we check for type equality\n        if not type(a) is type(b):  # noqa\n            raise TypeError(msg)\n", "path": "sktime/utils/validation/series.py"}], "after_files": [{"content": "#!/usr/bin/env python3 -u\n# -*- coding: utf-8 -*-\n\n\"\"\"Functions for checking input data.\"\"\"\n\n__author__ = [\"Markus L\u00f6ning\", \"Drishti Bhasin\"]\n__all__ = [\n    \"check_series\",\n    \"check_time_index\",\n    \"check_equal_time_index\",\n    \"check_consistent_index_type\",\n]\nimport numpy as np\nimport pandas as pd\n\n# We currently support the following types for input data and time index types.\nVALID_DATA_TYPES = (pd.DataFrame, pd.Series, np.ndarray)\nVALID_INDEX_TYPES = (pd.Int64Index, pd.RangeIndex, pd.PeriodIndex, pd.DatetimeIndex)\n\n\ndef _check_is_univariate(y, var_name=\"input\"):\n    \"\"\"Check if series is univariate.\"\"\"\n    if isinstance(y, pd.DataFrame):\n        nvars = y.shape[1]\n        if nvars > 1:\n            raise ValueError(\n                f\"{var_name} must be univariate, but found {nvars} variables.\"\n            )\n    if isinstance(y, np.ndarray) and y.ndim > 1 and y.shape[1] > 1:\n        raise ValueError(\n            f\"{var_name} must be univariate, but found np.ndarray with more than \"\n            \"one column\"\n        )\n\n\ndef _check_is_multivariate(Z, var_name=\"input\"):\n    \"\"\"Check if series is multivariate.\"\"\"\n    if isinstance(Z, pd.Series):\n        raise ValueError(f\"{var_name} must have 2 or more variables, but found 1.\")\n    if isinstance(Z, pd.DataFrame):\n        nvars = Z.shape[1]\n        if nvars < 2:\n            raise ValueError(\n                f\"{var_name} must have 2 or more variables, but found {nvars}.\"\n            )\n    if isinstance(Z, np.ndarray):\n        if Z.ndim == 1 or (Z.ndim == 2 and Z.shape[1] == 1):\n            raise ValueError(f\"{var_name} must have 2 or more variables, but found 1.\")\n\n\ndef check_series(\n    Z,\n    enforce_univariate=False,\n    enforce_multivariate=False,\n    allow_empty=False,\n    allow_numpy=True,\n    allow_None=True,\n    enforce_index_type=None,\n    allow_index_names=False,\n    var_name=\"input\",\n):\n    \"\"\"Validate input data to be a valid mtype for Series.\n\n    Parameters\n    ----------\n    Z : pd.Series, pd.DataFrame, np.ndarray, or None\n        Univariate or multivariate time series.\n    enforce_univariate : bool, default = False\n        If True, multivariate Z will raise an error.\n    enforce_multivariate: bool, default = False\n        If True, univariate Z will raise an error.\n    allow_empty : bool, default = False\n        whether a container with zero samples is allowed\n    allow_numpy : bool, default = True\n        whether no error is raised if Z is in a valid numpy.ndarray format\n    allow_None : bool, default = True\n        whether no error is raised if Z is None\n    enforce_index_type : type, default = None\n        type of time index\n    allow_index_names : bool, default = False\n        If False, names of Z.index will be set to None\n    var_name : str, default = \"input\" - variable name printed in error messages\n\n    Returns\n    -------\n    Z : pd.Series, pd.DataFrame, np.ndarray, or None\n        Validated time series - a reference to the input Z\n\n    Raises\n    ------\n    TypeError - if Z is not in a valid type or format for scitype Series\n    if enforce_univariate is True:\n        ValueError if Z has 2 or more columns\n    if enforce_multivariate is True:\n        ValueError if Z has 1 column\n    if allow_numpy is false:\n        TypeError - if Z is of type np.ndarray\n    if allow_empty is false:\n        ValueError - if Z has length 0\n    if allow_None is false:\n        ValueError - if Z is None\n    if enforce_index_type is not None and Z is pandas type:\n        ValueError - if Z has index type other than enforce_index_type\n    \"\"\"\n    if Z is None:\n        if allow_None:\n            return Z\n        else:\n            raise ValueError(var_name + \" cannot be None\")\n\n    # Check if pandas series or numpy array\n    if not allow_numpy:\n        valid_data_types = tuple(\n            filter(lambda x: x is not np.ndarray, VALID_DATA_TYPES)\n        )\n    else:\n        valid_data_types = VALID_DATA_TYPES\n\n    if not isinstance(Z, valid_data_types):\n        raise TypeError(\n            f\"{var_name} must be a one of {valid_data_types}, but found type: {type(Z)}\"\n        )\n\n    if enforce_univariate and enforce_multivariate:\n        raise ValueError(\n            \"`enforce_univariate` and `enforce_multivariate` cannot both be set to \"\n            \"True.\"\n        )\n\n    if enforce_univariate:\n        _check_is_univariate(Z, var_name=var_name)\n\n    if enforce_multivariate:\n        _check_is_multivariate(Z, var_name=var_name)\n\n    # check time index if input data is not an NumPy ndarray\n    if not isinstance(Z, np.ndarray):\n        check_time_index(\n            Z.index,\n            allow_empty=allow_empty,\n            enforce_index_type=enforce_index_type,\n            var_name=var_name,\n        )\n\n    if not allow_index_names and not isinstance(Z, np.ndarray):\n        Z.index.names = [None for name in Z.index.names]\n\n    return Z\n\n\ndef check_time_index(\n    index, allow_empty=False, enforce_index_type=None, var_name=\"input\"\n):\n    \"\"\"Check time index.\n\n    Parameters\n    ----------\n    index : pd.Index or np.array\n        Time index\n    allow_empty : bool, optional (default=False)\n        If False, empty `index` raises an error.\n    enforce_index_type : type, optional (default=None)\n        type of time index\n    var_name : str, default = \"input\" - variable name printed in error messages\n\n    Returns\n    -------\n    time_index : pd.Index\n        Validated time index - a reference to the input index\n    \"\"\"\n    if isinstance(index, np.ndarray):\n        index = pd.Index(index)\n\n    # We here check for type equality because isinstance does not\n    # work reliably because index types inherit from each other.\n    if not type(index) in VALID_INDEX_TYPES:\n        raise NotImplementedError(\n            f\"{type(index)} is not supported for {var_name}, use \"\n            f\"one of {VALID_INDEX_TYPES} instead.\"\n        )\n\n    if enforce_index_type and type(index) is not enforce_index_type:\n        raise NotImplementedError(\n            f\"{type(index)} is not supported for {var_name}, use \"\n            f\"type: {enforce_index_type} instead.\"\n        )\n\n    # Check time index is ordered in time\n    if not index.is_monotonic:\n        raise ValueError(\n            f\"The (time) index of {var_name} must be sorted monotonically increasing, \"\n            f\"but found: {index}\"\n        )\n\n    # Check that index is not empty\n    if not allow_empty and len(index) < 1:\n        raise ValueError(\n            f\"{var_name} must contain at least some values, but found none.\"\n        )\n\n    return index\n\n\ndef check_equal_time_index(*ys):\n    \"\"\"Check that time series have the same (time) indices.\n\n    Parameters\n    ----------\n    *ys : tuple of pd.Series, pd.DataFrame or np.ndarray, or None\n        One or more time series\n\n    Raises\n    ------\n    ValueError\n        If there are at least two no=-None entries of ys\n            of which pandas indices are not the same\n            np.ndarray are considered having integer range index on axis 0\n    \"\"\"\n    # None entries are ignored\n    y_not_None = [y for y in ys if y is not None]\n\n    # if there is no or just one element, there is nothing to compare\n    if len(y_not_None) < 2:\n        return None\n\n    # only validate indices if data is passed as pd.Series\n    if isinstance(y_not_None[0], np.ndarray):\n        first_index = pd.Index(range(len(y_not_None[0])))\n    else:\n        first_index = y_not_None[0].index\n\n    check_time_index(first_index)\n\n    for y in y_not_None[1:]:\n        if isinstance(y, np.ndarray):\n            y_index = pd.Index(y)\n        else:\n            y_index = y.index\n\n        check_time_index(y_index)\n\n        if not first_index.equals(y_index):\n            raise ValueError(\"Some (time) indices are not the same.\")\n\n\ndef _is_int_index(index):\n    \"\"\"Check if index type is one of pd.RangeIndex or pd.Int64Index.\"\"\"\n    return type(index) in (pd.Int64Index, pd.RangeIndex)\n\n\ndef check_consistent_index_type(a, b):\n    \"\"\"Check that two indices have consistent types.\n\n    Parameters\n    ----------\n    a : pd.Index\n        Index being checked for consistency\n    b : pd.Index\n        Index being checked for consistency\n\n    Raises\n    ------\n    TypeError\n        If index types are inconsistent\n    \"\"\"\n    msg = (\n        \"Found series with inconsistent index types, please make sure all \"\n        \"series have the same index type.\"\n    )\n\n    if _is_int_index(a):\n        if not _is_int_index(b):\n            raise TypeError(msg)\n\n    else:\n        # check types, note that isinstance() does not work here because index\n        # types inherit from each other, hence we check for type equality\n        if not type(a) is type(b):  # noqa\n            raise TypeError(msg)\n", "path": "sktime/utils/validation/series.py"}]}