Browse Source

pc datatable fix for python <=3.8 (#949)

Elijah Ahianyo 2 năm trước cách đây
mục cha
commit
0d51f58c9f
2 tập tin đã thay đổi với 31 bổ sung0 xóa
  1. 3 0
      pynecone/utils/types.py
  2. 28 0
      tests/test_utils.py

+ 3 - 0
pynecone/utils/types.py

@@ -3,6 +3,7 @@
 from __future__ import annotations
 
 import contextlib
+import typing
 from typing import Any, Callable, Tuple, Type, Union, _GenericAlias  # type: ignore
 
 from pynecone.base import Base
@@ -135,6 +136,8 @@ def is_dataframe(value: Type) -> bool:
     Returns:
         Whether the value is a dataframe.
     """
+    if is_generic_alias(value) or value == typing.Any:
+        return False
     return value.__name__ == "DataFrame"
 
 

+ 28 - 0
tests/test_utils.py

@@ -1,3 +1,4 @@
+import typing
 from typing import Any, List, Union
 
 import pytest
@@ -357,3 +358,30 @@ def test_format_ref(name, expected):
         expected: The expected formatted name.
     """
     assert format.format_ref(name) == expected
+
+
+class DataFrame:
+    """A Fake pandas DataFrame class."""
+
+    pass
+
+
+@pytest.mark.parametrize(
+    "class_type,expected",
+    [
+        (list, False),
+        (int, False),
+        (dict, False),
+        (DataFrame, True),
+        (typing.Any, False),
+        (typing.List, False),
+    ],
+)
+def test_is_dataframe(class_type, expected):
+    """Test that a type name is DataFrame.
+
+    Args:
+        class_type: the class type.
+        expected: whether type name is DataFrame
+    """
+    assert types.is_dataframe(class_type) == expected