Repository: streamlit/streamlit

Issue:
Unable to create Pandas Series in cached functions
# Summary
Unable to generate Pandas Series in cached functions.

# Steps to reproduce
Run this code:
```
import streamlit as st 
import pandas as pd

@st.cache
def test_function():
    series = pd.Series()
    return series

test_function()
```

## Expected behavior:
Expect to be able to create Pandas Series inside of cached functions.

## Actual behavior:
Following error is thrown:
```
TypeError: stat: path should be string, bytes, os.PathLike or integer, not property
File "/home/jforth/anaconda3/envs/AutoDraft/lib/python3.7/site-packages/streamlit/ScriptRunner.py", line 317, in _run_script exec(code, module.__dict__)
File "/home/jforth/Documents/streamlit_test.py", line 9, in <module> test_function()
File "/home/jforth/anaconda3/envs/AutoDraft/lib/python3.7/site-packages/streamlit/caching.py", line 393, in wrapped_func code_hasher.update(func)
File "/home/jforth/anaconda3/envs/AutoDraft/lib/python3.7/site-packages/streamlit/hashing.py", line 159, in update self._update(self.hasher, obj, context)
File "/home/jforth/anaconda3/envs/AutoDraft/lib/python3.7/site-packages/streamlit/hashing.py", line 190, in _update b = self.to_bytes(obj, context)
File "/home/jforth/anaconda3/envs/AutoDraft/lib/python3.7/site-packages/streamlit/hashing.py", line 179, in to_bytes b = self._to_bytes(obj, context)
File "/home/jforth/anaconda3/envs/AutoDraft/lib/python3.7/site-packages/streamlit/hashing.py", line 259, in _to_bytes h.update(self._code_to_bytes(obj.__code__, context))
File "/home/jforth/anaconda3/envs/AutoDraft/lib/python3.7/site-packages/streamlit/hashing.py", line 316, in _code_to_bytes self._update(h, ref, context)
File "/home/jforth/anaconda3/envs/AutoDraft/lib/python3.7/site-packages/streamlit/hashing.py", line 190, in _update b = self.to_bytes(obj, context)
File "/home/jforth/anaconda3/envs/AutoDraft/lib/python3.7/site-packages/streamlit/hashing.py", line 179, in to_bytes b = self._to_bytes(obj, context)
File "/home/jforth/anaconda3/envs/AutoDraft/lib/python3.7/site-packages/streamlit/hashing.py", line 236, in _to_bytes isinstance(obj, io.IOBase) or os.path.exists(obj.name)):
File "/home/jforth/anaconda3/envs/AutoDraft/lib/python3.7/genericpath.py", line 19, in exists os.stat(path)
```

## Is this a regression?
Not sure.

# Debug info
- Streamlit version: 0.45.0
- Python version: 3.7.4
- Using Conda
- OS version: Ubuntu 19.04
- Browser version: Chrome 77.0.3865.75 



Discussion:

Resolving patch:
diff --git a/lib/streamlit/hashing.py b/lib/streamlit/hashing.py
--- a/lib/streamlit/hashing.py
+++ b/lib/streamlit/hashing.py
@@ -230,6 +230,9 @@ def _to_bytes(self, obj, context):
             return b"bool:1"
         elif obj is False:
             return b"bool:0"
+        elif util.is_type(obj, "pandas.core.frame.Series"):
+            import pandas as pd
+            return pd.util.hash_pandas_object(obj).sum()
         elif util.is_type(obj, "pandas.core.frame.DataFrame"):
             import pandas as pd
 
@@ -251,7 +254,8 @@ def _to_bytes(self, obj, context):
         elif inspect.isbuiltin(obj):
             return self.to_bytes(obj.__name__)
         elif hasattr(obj, "name") and (
-            isinstance(obj, io.IOBase) or os.path.exists(obj.name)
+            isinstance(obj, io.IOBase) or
+            (isinstance(obj.name, string_types) and os.path.exists(obj.name))
         ):
             # Hash files as name + last modification date + offset.
             h = hashlib.new(self.name)


Test patch:
diff --git a/lib/tests/streamlit/hashing_test.py b/lib/tests/streamlit/hashing_test.py
--- a/lib/tests/streamlit/hashing_test.py
+++ b/lib/tests/streamlit/hashing_test.py
@@ -69,7 +69,7 @@ def test_builtins(self):
         self.assertEqual(get_hash(abs), get_hash(abs))
         self.assertNotEqual(get_hash(abs), get_hash(type))
 
-    def test_pandas(self):
+    def test_pandas_dataframe(self):
         df1 = pd.DataFrame({"foo": [12]})
         df2 = pd.DataFrame({"foo": [42]})
         df3 = pd.DataFrame({"foo": [12]})
@@ -77,6 +77,14 @@ def test_pandas(self):
         self.assertEqual(get_hash(df1), get_hash(df3))
         self.assertNotEqual(get_hash(df1), get_hash(df2))
 
+    def test_pandas_series(self):
+        series1 = pd.Series([1, 2])
+        series2 = pd.Series([1, 3])
+        series3 = pd.Series([1, 2])
+
+        self.assertEqual(get_hash(series1), get_hash(series3))
+        self.assertNotEqual(get_hash(series1), get_hash(series2))
+
     def test_numpy(self):
         np1 = np.zeros(10)
         np2 = np.zeros(11)