Skip to content

parse_wpc_surface_bulletin does not handle StringIO object, results in AttributeError: 'str' object has no attribute 'decode' #3923

@akrherz

Description

@akrherz

What went wrong?

The docstring for parse_wpc_surface_bulletin says

bulletin : str or file-like object
If str, the name of the file to be opened. If bulletin is a file-like object, this will be read from directly.

but passing it a StringIO instance yields an AttributeError

Operating System

Linux

Version

1.1.0.post367+g05e1d20f6

Python Version

3.13

Code to Reproduce

from io import StringIO
from metpy.io import parse_wpc_surface_bulletin

sio = StringIO("""VALID 062818Z
HIGHS 1022 3961069 1020 3851069 1026 3750773 1022 4430845 1019 5520728
LOWS 1016 4510934 1002 3441145 1003 4271229 1002 4471230 1009 4631181
TROF 2971023 2831018 2691008 I2531003
TROF 2911100 2681082 2511055 2431024
 """)
parse_wpc_surface_bulletin(sio, year=2000)

Errors, Traceback, and Logs

Traceback (most recent call last):
  File "metpy_example.py", line 11, in <module>
    parse_wpc_surface_bulletin(sio, year=2000)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "/home/akrherz/projects/MetPy/src/metpy/io/text.py", line 102, in parse_wpc_surface_bulletin
    text = file.read().decode('utf-8')
           ^^^^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'decode'. Did you mean: 'encode'?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: BugSomething is not working like it should

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions