Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update_cmds fixes for py3 #139

Merged
merged 3 commits into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions kadi/update_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
import os
import argparse
import difflib
import pickle

import numpy as np
import tables
from six.moves import cPickle as pickle
import six

import pyyaks.logger
import Ska.DBI
Expand All @@ -15,6 +14,7 @@
from Chandra.cmd_states.cmd_states import _tl_to_bs_cmds
from . import occweb
from .paths import IDX_CMDS_PATH, PARS_DICT_PATH
from . import __version__

MIN_MATCHING_BLOCK_SIZE = 500
BACKSTOP_CACHE = {}
Expand Down Expand Up @@ -69,6 +69,8 @@ def get_opt(args=None):
default=False,
action='store_true',
help="Store or get files via ftp (implied for --occ)")
parser.add_argument('--version', action='version',
version='%(prog)s {version}'.format(version=__version__))

args = parser.parse_args(args)
return args
Expand Down Expand Up @@ -105,18 +107,15 @@ def fix_nonload_cmds(nl_cmds):
if cmd['msid'] is not None:
new_cmd['params']['msid'] = str(cmd['msid'])

# De-unicode and de-numpy (otherwise unpickling on PY3 has problems).
# De-numpy (otherwise unpickling on PY3 has problems).
if 'params' in cmd:
params = new_cmd['params']
for key, val in cmd['params'].items():
key = str(key)
if isinstance(val, six.string_types):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous logic was that val might be a Py2 str or unicode, and it was necessary to coerce to str. See the dump above of an example of the data structure. In Py3 none of this needed and instead we just try using the numpy item() method to coerce to pure-Python.

val = str(val)
else:
try:
val = val.item()
except Exception:
pass
try:
val = val.item()
except AttributeError:
pass
params[key] = val

new_cmds.append(new_cmd)
Expand Down Expand Up @@ -316,7 +315,10 @@ def add_h5_cmds(h5file, idx_cmds):
# Define the column names that specify a complete and unique row
key_names = ('date', 'type', 'tlmsid', 'scs', 'step', 'timeline_id', 'vcdu')

h5d_recent_vals = [tuple(str(row[x]) for x in key_names) for row in h5d_recent]
h5d_recent_vals = [tuple(
row[x].decode('ascii') if isinstance(row[x], bytes) else str(row[x])
for x in key_names)
for row in h5d_recent]
idx_cmds_vals = [tuple(str(x) for x in row[1:]) for row in idx_cmds]

diff = difflib.SequenceMatcher(a=h5d_recent_vals, b=idx_cmds_vals, autojunk=False)
Expand Down
2 changes: 1 addition & 1 deletion kadi/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
# SET THESE VALUES
############################
# Major, Minor, Bugfix, Dev
VERSION = (4, 18, 1, False)
VERSION = (4, 19, None, False)


class SemanticVersion(object):
Expand Down