Skip to content

Commit

Permalink
Py2 fix for DataFrameCache - see apache#3302
Browse files Browse the repository at this point in the history
  • Loading branch information
rhunwicks committed Oct 5, 2017
1 parent b24a700 commit 3610ac0
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions contrib/connectors/pandas/cache.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from io import open
import json
Expand All @@ -13,6 +14,7 @@
import pickle

import pandas as pd
from six import u

from werkzeug.contrib.cache import FileSystemCache
from werkzeug.posixemulation import rename
Expand Down Expand Up @@ -55,7 +57,7 @@ def _prune(self):
for idx, cname in enumerate(entries):
mname = os.path.splitext(cname)[0] + self._fs_metadata_suffix
try:
with open(mname, 'r') as f:
with open(mname, 'r', encoding='utf-8') as f:
metadata = json.load(f)
except (IOError, OSError):
metadata = {'expires': -1}
Expand Down Expand Up @@ -83,7 +85,7 @@ def get(self, key):
cname = filename + self._fs_cache_suffix
mname = filename + self._fs_metadata_suffix
try:
with open(mname, 'r') as f:
with open(mname, 'r', encoding='utf-8') as f:
metadata = json.load(f)
except (IOError, OSError):
metadata = {'expires': -1}
Expand Down Expand Up @@ -133,8 +135,8 @@ def set(self, key, value, timeout=None):
metadata['format'] = 'pickle'
rename(tmp, cname)
os.chmod(cname, self._mode)
with open(mname, 'w') as f:
json.dump(metadata, f)
with open(mname, 'w', encoding='utf-8') as f:
f.write(u(json.dumps(metadata)))
os.chmod(mname, self._mode)
except (IOError, OSError):
return False
Expand All @@ -158,7 +160,7 @@ def has(self, key):
cname = filename + self._fs_cache_suffix
mname = filename + self._fs_metadata_suffix
try:
with open(mname, 'r') as f:
with open(mname, 'r', encoding='utf-8') as f:
metadata = json.load(f)
except (IOError, OSError):
metadata = {'expires': -1}
Expand Down

0 comments on commit 3610ac0

Please sign in to comment.