class_docstr: stock_id : str
  amount : float
  start_time : pd.Timestamp
      closed start time for order trading
  end_time : pd.Timestamp
      closed end time for order trading
  direction : int
      Order.SELL for sell; Order.BUY for buy
  factor : float
          presents the weight factor assigned in Exchange()
class_docstr_tok: ["stock_id",":","str","amount",":","float","start_time",":","pd.Timestamp","closed","start","time","for","order","trading","end_time",":","pd.Timestamp","closed","end","time","for","order","trading","direction",":","int","Order.SELL","for","sell",";","Order.BUY","for","buy","factor",":","float","presents","the","weight","factor","assigned","in","Exchange","(",")"]
code: def parse_dir(
      direction: Union[str, int, np.integer, OrderDir, np.ndarray]
  ) -> Union[OrderDir, np.ndarray]:
      if isinstance(direction, OrderDir):
          return direction
      elif isinstance(direction, (int, float, np.integer, np.floating)):
          return Order.BUY if direction > 0 else Order.SELL
      elif isinstance(direction, str):
          dl = direction.lower().strip()
          if dl == "sell":
              return OrderDir.SELL
          elif dl == "buy":
              return OrderDir.BUY
          else:
              raise NotImplementedError(
                  f"This type of input is not supported"
              )
      elif isinstance(direction, np.ndarray):
          direction_array = direction.copy()
          direction_array[direction_array > 0] = Order.BUY
          direction_array[direction_array <= 0] = Order.SELL
          return direction_array
      else:
          raise NotImplementedError(
              f"This type of input is not supported"
          )
  
imports: from __future__ import annotations
  from abc import abstractmethod
  from datetime import time
  from enum import IntEnum
  from typing import TYPE_CHECKING, Any, ClassVar, Generic, List, Optional, Tuple, TypeVar, Union, cast
  from qlib.backtest.utils import TradeCalendarManager
  from qlib.data.data import Cal
  from qlib.log import get_module_logger
  from qlib.utils.time import concat_date_time, epsilon_change
  from dataclasses import dataclass
  import numpy
  import pandas
label_desc: Use image node_id 5 for calling the Order obj's underlying member method code with example usage: obj.parse_dir(direction) and returns: direction, unknown, OrderDir, direction_array, OrderDir