I am using Python doctests for a code which is supposed to work with Python 2 and Python 3. All works fine except for when I work with numpy array containing strings. With Python 3, the following is correct:
>>> np.array(["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"]) # doctest: +NORMALIZE_WHITESPACE
array(['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep',
'oct', 'nov', 'dec'],
dtype='<U3')
With Python 2, this result is expected:
array(['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep',
'oct', 'nov', 'dec'],
dtype='|S3')
Note the <U3
vs. |S3
difference.
Is there any easy way to tweak my code to be able to pass the tests in both Python versions? I want to do the lease intrusive changes possible. As doctests are also targeting users (so they can see how to use the code) I do not want too complicated or misleading code to give them wrong impression of the correct usage.