瀏覽代碼

Handle dataframe base vars (#878)

Nikhil Rao 2 年之前
父節點
當前提交
15485f0716
共有 1 個文件被更改,包括 12 次插入0 次删除
  1. 12 0
      pynecone/var.py

+ 12 - 0
pynecone/var.py

@@ -704,6 +704,9 @@ class BaseVar(Var, Base):
 
         Returns:
             The default value of the var.
+
+        Raises:
+            ImportError: If the var is a dataframe and pandas is not installed.
         """
         type_ = (
             self.type_.__origin__ if types.is_generic_alias(self.type_) else self.type_
@@ -720,6 +723,15 @@ class BaseVar(Var, Base):
             return {}
         if issubclass(type_, tuple):
             return ()
+        if types.is_dataframe(type_):
+            try:
+                import pandas as pd
+
+                return pd.DataFrame()
+            except ImportError as e:
+                raise ImportError(
+                    "Please install pandas to use dataframes in your app."
+                ) from e
         return set() if issubclass(type_, set) else None
 
     def get_setter_name(self, include_state: bool = True) -> str: