Repository: sktime/sktime

Issue:
[BUG] using custom `extract_path` does not work in `sktime.datasets.load_UCR_UEA_dataset`
**Describe the bug**
<!--
A clear and concise description of what the bug is.
-->
Error occurs when I use my own download path.

**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
-->

```python
#my code
x, y = load_UCR_UEA_dataset(name="xxx", return_X_y=True, return_type="numpy3d", extract_path="data/xxx")

#traceback
Traceback (most recent call last):
  File "main.py", line 10, in <module>
    dataloader.load_data("Synthetic Control", "data/Synthetic Control")
  File "dataloader.py", line 4, in load_data
    x, y = load_UCR_UEA_dataset(name=dataset_name, return_X_y=True, return_type="numpy3d", extract_path=stored_path)
  File "/home/anaconda3/envs/pt/lib/python3.9/site-packages/sktime/datasets/_single_problem_loaders.py", line 124, in load_UCR_UEA_dataset
    return _load_dataset(name, split, return_X_y, return_type, extract_path)
  File "/home/anaconda3/envs/pt/lib/python3.9/site-packages/sktime/datasets/_data_io.py", line 249, in _load_dataset
    if name in _list_available_datasets(check_path):
UnboundLocalError: local variable 'check_path' referenced before assignment

#original code
if extract_path is None:
    # default for first check is sktime/datasets/data
    check_path = os.path.join(MODULE, "data")

def _get_data_from(path):
    return _load_provided_dataset(name, split, return_X_y, return_type, path)

# if the dataset exists in check_path = sktime/datasets/data, retrieve it from there
if name in _list_available_datasets(check_path):
    return _get_data_from(check_path)

# now we know the dataset is not in check_path
# so we need to check whether it is already in the download/cache path
# download path is extract_path/local_data, defaults to sktime/datasets/local_data
if extract_path is None:
    extract_path = os.path.join(MODULE, "local_data")

# in either case below, we need to ensure the directory exists
_mkdir_if_not_exist(extract_path)

# search if the dataset is already in the extract path after download
if name in _list_available_datasets(extract_path):
    return _get_data_from(extract_path)

```

**Expected behavior**
<!--
A clear and concise description of what you expected to happen.
-->
When I trace back to the original code, "check_path" is defined only when the extract_path is not specified. If I use my own extract_path, "check_path" is not defined when checking available datasets.

**Versions**
<details>

<!--
Please run the following code snippet and paste the output here:

from sktime import show_versions; show_versions()
-->
the newest version
</details>

<!-- Thanks for contributing! -->



Discussion:
should it be `else check_path = extract_path`?
> should it be `else check_path = extract_path`?

I suppose.
Would appreciate a PR then, tested on your use case - and possibly a test added to the code base, if you have time!

Resolving patch:
diff --git a/sktime/datasets/_data_io.py b/sktime/datasets/_data_io.py
--- a/sktime/datasets/_data_io.py
+++ b/sktime/datasets/_data_io.py
@@ -241,6 +241,8 @@ def _load_dataset(name, split, return_X_y, return_type=None, extract_path=None):
     if extract_path is None:
         # default for first check is sktime/datasets/data
         check_path = os.path.join(MODULE, "data")
+    else:
+        check_path = extract_path
 
     def _get_data_from(path):
         return _load_provided_dataset(name, split, return_X_y, return_type, path)


Test patch:
diff --git a/sktime/datasets/tests/test_data_io.py b/sktime/datasets/tests/test_data_io.py
--- a/sktime/datasets/tests/test_data_io.py
+++ b/sktime/datasets/tests/test_data_io.py
@@ -84,6 +84,16 @@ def test_load_UCR_UEA_dataset():
     assert X.shape == (42, 1) and y.shape == (42,)
 
 
+def test_load_UCR_UEA_local():
+    """Tests load_UCR_UEA_dataset looks for local file if extract_path is set.
+
+    A FileNotFoundError indicates the function looked for the file and everything up
+    to that point went fine.
+    """
+    with pytest.raises(FileNotFoundError):
+        load_UCR_UEA_dataset(name="UnitTest", extract_path=" ")
+
+
 _CHECKS = {
     "uschange": {
         "columns": ["Income", "Production", "Savings", "Unemployment"],