code: def from_str(cls, s):
      stream = cls(
          [
              Token(name, value, match)
              for match in re.finditer(cls.RX, s)
              for name, value in valfilter(
                  bool, match.groupdict()
              ).items()
              if name != "WHITESPACE"
          ]
      )
  
      for token in stream:
          if token.name == "INVALID":
              raise ValueError(f"Invalid token: {token}")
  
      return stream
  
imports: import re
  from dataclasses import dataclass, InitVar, field
  from itertools import chain
  from typing import Any, Dict, List, Union, Optional, ClassVar
  import numpy
  from toolz import valfilter, valmap
label_desc: Use image node_id 1 for calling the TokenStream obj's underlying member method code with example usage: obj.from_str(cls, s) and returns: stream