Repository: ImperialCollegeLondon/pycsvy

Issue:
Error occurs if `pandas` is not installed
I'm trying to use pycsvy with FINESSE, which doesn't use pandas, and I'm getting the following error:

```
Exception has occurred: TypeError
Tuple[t0, t1, ...]: each t must be a type. Got NotImplemented.
  File "/home/alex/code/FINESSE/finesse/hardware/data_file_writer.py", line 9, in <module>
    from csvy import Writer
  File "/home/alex/code/FINESSE/finesse/hardware/__init__.py", line 13, in <module>
    from . import data_file_writer  # noqa
  File "/home/alex/code/FINESSE/finesse/__init__.py", line 16, in run
    from . import hardware  # noqa
  File "/home/alex/code/FINESSE/finesse/__main__.py", line 5, in <module>
    run()
TypeError: Tuple[t0, t1, ...]: each t must be a type. Got NotImplemented.
```

It seems that Python is expecting a type and `NotImplemented` doesn't cound.

In case it's relevant: I'm using Python 3.10.

Discussion:
alexdewar: This will need rebasing onto #52 to fix failing tests.
dalonsoa: Not sure why it is happy with `None` and not with `NotImplemented`. `None` is not a type, either...

Patch:
diff --git a/csvy/readers.py b/csvy/readers.py
index 5b98c41..e51bcd9 100644
--- a/csvy/readers.py
+++ b/csvy/readers.py
@@ -7,7 +7,7 @@ import yaml
 try:
     from numpy.typing import NDArray
 except ModuleNotFoundError:
-    NDArray = NotImplemented  # type: ignore
+    NDArray = None  # type: ignore
     logging.getLogger().debug(
         "Numpy is not installed. Reading into an array will not work."
     )
@@ -15,7 +15,7 @@ except ModuleNotFoundError:
 try:
     from pandas import DataFrame
 except ModuleNotFoundError:
-    DataFrame = NotImplemented  # type: ignore
+    DataFrame = None  # type: ignore
     logging.getLogger().debug(
         "Pandas is not installed. Reading into a DataFrame will not work."
     )
@@ -115,7 +115,7 @@ def read_to_array(
     Returns:
         Tuple containing: The numpy array and the header as a dictionary.
     """
-    if NDArray is NotImplemented:
+    if NDArray is None:
         raise ModuleNotFoundError(
             "Module numpy is not present. Install it to read data into an array."
         )
@@ -153,7 +153,7 @@ def read_to_dataframe(
     Returns:
         Tuple containing: The pandas DataFrame and the header as a dictionary.
     """
-    if DataFrame is NotImplemented:
+    if DataFrame is None:
         raise ModuleNotFoundError(
             "Module pandas is not present. Install it to read data into DataFrame."
         )


Test patch:
diff --git a/tests/test_read.py b/tests/test_read.py
index 1204f7f..32bf32d 100644
--- a/tests/test_read.py
+++ b/tests/test_read.py
@@ -59,7 +59,7 @@ def test_read_to_array(array_data_path):
 
     import csvy.readers as readers
 
-    readers.NDArray = NotImplemented
+    readers.NDArray = None
 
     with pytest.raises(ModuleNotFoundError):
         read_to_array(array_data_path)
@@ -78,7 +78,7 @@ def test_read_to_dataframe(data_path):
 
     import csvy.readers as readers
 
-    readers.DataFrame = NotImplemented
+    readers.DataFrame = None
 
     with pytest.raises(ModuleNotFoundError):
         read_to_dataframe(data_path)