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

FIX: fix Species Python 2 unicode support #166

Merged
merged 2 commits into from Mar 20, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions pycalphad/tests/test_variables.py
@@ -0,0 +1,10 @@
"""
Test variables module.
"""

from pycalphad import variables as v


def test_species_parse_unicode_strings():
"""Species should properly parse unicode strings."""
s = v.Species(u"MG")
9 changes: 8 additions & 1 deletion pycalphad/variables.py
Expand Up @@ -3,6 +3,13 @@
Classes and constants for representing thermodynamic variables.
"""

import sys
# Python 2 vs 3 string types in isinstance
if sys.version_info[0] >= 3:
string_type = str
else:
string_type = basestring

import itertools
from sympy import Float, Symbol
from pyparsing import ParseException
Expand Down Expand Up @@ -48,7 +55,7 @@ def __new__(cls, name, constituents=None, charge=0):
new_self.charge = 0
return new_self

if isinstance(arg, str):
if isinstance(arg, string_type):
try:
parse_list = chemical_formula.parseString(arg.upper())
except ParseException:
Expand Down