Thanks to visit codestin.com
Credit goes to github.com

Skip to content

%s -> %r else if invalid char unable to print error #4551

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

Merged
merged 1 commit into from
Jun 27, 2015

Conversation

mdipierro
Copy link
Contributor

No description provided.

@WeatherGod
Copy link
Member

attn: @mdboom

On Tue, Jun 23, 2015 at 2:12 PM, mdipierro [email protected] wrote:


You can view, comment on, or merge this pull request online at:

#4551
Commit Summary

  • %s -> %r else if invalid char unable to print error

File Changes

Patch Links:


Reply to this email directly or view it on GitHub
#4551.

@tacaswell
Copy link
Member

Looks reasonable to me, what conditions caused this to matter?

@tacaswell tacaswell added this to the next point release milestone Jun 23, 2015
@mdipierro
Copy link
Contributor Author

I upgraded anaconda on Mac and I started getting:

Found an unknown keyword in AFM header (was Georgia)
Found an unknown keyword in AFM header (was Georgia)
Found an unknown keyword in AFM header (was Georgia)
Found an unknown keyword in AFM header (was Normal)
Found an unknown keyword in AFM header (was Georgia)
Found an unknown keyword in AFM header (was Georgia)
Found an unknown keyword in AFM header (was Georgia)
Found an unknown keyword in AFM header (was Normal)
Traceback (most recent call last):
....
import matplotlib.backend_bases as backend_bases
File "/Users/massimodipierro/anaconda/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 56, in
import matplotlib.textpath as textpath
File "/Users/massimodipierro/anaconda/lib/python2.7/site-packages/matplotlib/textpath.py", line 19, in
import matplotlib.font_manager as font_manager
File "/Users/massimodipierro/anaconda/lib/python2.7/site-packages/matplotlib/font_manager.py", line 1415, in
_rebuild()
File "/Users/massimodipierro/anaconda/lib/python2.7/site-packages/matplotlib/font_manager.py", line 1400, in _rebuild
fontManager = FontManager()
File "/Users/massimodipierro/anaconda/lib/python2.7/site-packages/matplotlib/font_manager.py", line 1059, in init
self.afmlist = createFontList(self.afmfiles, fontext='afm')
File "/Users/massimodipierro/anaconda/lib/python2.7/site-packages/matplotlib/font_manager.py", line 568, in createFontList
font = afm.AFM(fh)
File "/Users/massimodipierro/anaconda/lib/python2.7/site-packages/matplotlib/afm.py", line 346, in init
parse_afm(fh)
File "/Users/massimodipierro/anaconda/lib/python2.7/site-packages/matplotlib/afm.py", line 333, in parse_afm
dhead = _parse_header(fh)
File "/Users/massimodipierro/anaconda/lib/python2.7/site-packages/matplotlib/afm.py", line 172, in _parse_header
print('Found an unknown keyword in AFM header (was %s)' % key,
UnicodeDecodeError: 'ascii' codec can't decode byte 0xa9 in position 0: ordinal not in range(128)

After the change the output was:

Found an unknown keyword in AFM header (was 'Georgia')
Found an unknown keyword in AFM header (was 'Georgia')
Found an unknown keyword in AFM header (was 'Georgia')
Found an unknown keyword in AFM header (was 'Normal')
Found an unknown keyword in AFM header (was '\xa9')

I am not sure how and were \xa9 got in there. It does not happen in my code.

@tacaswell
Copy link
Member

No, that is coming out of parsing the AFM files. Can you tell which font it is that is causing trouble?

For reference the offending character:

In [12]: print('\xa9')
©

@mdipierro
Copy link
Contributor Author

thanks for responding so quickly. :-)
How do I check which font?

@tacaswell
Copy link
Member

If you can get into debug mode you can walk the trace back up until it shows you the file path in createFontList. The other option is to just add a print statement into font_manager.createFontList and which ever one it prints out last is the problem ;)

@mdipierro
Copy link
Contributor Author

...
/Users/massimodipierro/anaconda/lib/python2.7/site-packages/matplotlib/mpl-data/fonts/pdfcorefonts/Times-Bold.afm
/Users/massimodipierro/anaconda/lib/python2.7/site-packages/matplotlib/mpl-data/fonts/afm/phvl8a.afm
/Library/Fonts/georgia.afm
Found an unknown keyword in AFM header (was 'Georgia')
Found an unknown keyword in AFM header (was 'Georgia')
Found an unknown keyword in AFM header (was 'Georgia')
Found an unknown keyword in AFM header (was 'Normal')
Found an unknown keyword in AFM header (was '\xa9')
/usr/X11/lib/X11/fonts/Type1/UTB_____.afm
/usr/X11/lib/X11/fonts/Type1/c0583bt_.afm
...

does it help?

@tacaswell
Copy link
Member

It looks like the offending file is /Library/Fonts/georgia.afm which does not seem to be a 'standard' font on OSX. It is probably worth sorting out if your file is badly formed or our parser is not complete (or both!), but not worth holding this PR up over.

tacaswell added a commit that referenced this pull request Jun 27, 2015
FIX: handle printing warning for non-ascii in afm headers
@tacaswell tacaswell merged commit 4a0af53 into matplotlib:master Jun 27, 2015
@tacaswell
Copy link
Member

@mdipierro Thank you!

@mdipierro
Copy link
Contributor Author

Thank you. Sorry for not responding sooner.

@jenshnielsen
Copy link
Member

Looks good to me. I just want to add for any future reference that this is similar to the issue observed in #3849 fixed by #3853 in the truetype font code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants