class_docstr: Partition parser for path-based partition formats.
  
  Path-based partition formats embed all partition keys and values directly in
  their dataset file paths.
  
  Two path partition formats are currently supported - `HIVE` and `DIRECTORY`.
  
  For `HIVE` Partitioning, all partition directories under the base directory
  will be discovered based on `{key1}={value1}/{key2}={value2}` naming
  conventions. Key/value pairs do not need to be presented in the same
  order across all paths. Directory names nested under the base directory that
  don't follow this naming condition will be considered unpartitioned. If a
  partition filter is defined, then it will be called with an empty input
  dictionary for each unpartitioned file.
  
  For `DIRECTORY` Partitioning, all directories under the base directory will
  be interpreted as partition values of the form `{value1}/{value2}`. An
  accompanying ordered list of partition field names must also be provided,
  where the order and length of all partition values must match the order and
  length of field names. Files stored directly in the base directory will
  be considered unpartitioned. If a partition filter is defined, then it will
  be called with an empty input dictionary for each unpartitioned file. For
  example, if the base directory is `"foo"`, then `"foo.csv"` and `"foo/bar.csv"`
  would be considered unpartitioned files but `"foo/bar/baz.csv"` would be associated
  with partition `"bar"`. If the base directory is undefined, then `"foo.csv"` would
  be unpartitioned, `"foo/bar.csv"` would be associated with partition `"foo"`, and
  "foo/bar/baz.csv" would be associated with partition `("foo", "bar")`.
class_docstr_tok: ["Partition","parser","for","path-based","partition","formats",".","Path-based","partition","formats","embed","all","partition","keys","and","values","directly","in","their","dataset","file","paths",".","Two","path","partition","formats","are","currently","supported","-","`","HIVE","`","and","`","DIRECTORY","`",".","For","`","HIVE","`","Partitioning",",","all","partition","directories","under","the","base","directory","will","be","discovered","based","on","`","{","key1","}","=","{","value1","}","\/","{","key2","}","=","{","value2","}","`","naming","conventions",".","Key\/value","pairs","do","not","need","to","be","presented","in","the","same","order","across","all","paths",".","Directory","names","nested","under","the","base","directory","that","do","n't","follow","this","naming","condition","will","be","considered","unpartitioned",".","If","a","partition","filter","is","defined",",","then","it","will","be","called","with","an","empty","input","dictionary","for","each","unpartitioned","file",".","For","`","DIRECTORY","`","Partitioning",",","all","directories","under","the","base","directory","will","be","interpreted","as","partition","values","of","the","form","`","{","value1","}","\/","{","value2","}","`",".","An","accompanying","ordered","list","of","partition","field","names","must","also","be","provided",",","where","the","order","and","length","of","all","partition","values","must","match","the","order","and","length","of","field","names",".","Files","stored","directly","in","the","base","directory","will","be","considered","unpartitioned",".","If","a","partition","filter","is","defined",",","then","it","will","be","called","with","an","empty","input","dictionary","for","each","unpartitioned","file",".","For","example",",","if","the","base","directory","is","`","``","foo","''","`",",","then","`","``","foo.csv","''","`","and","`","``","foo\/bar.csv","''","`","would","be","considered","unpartitioned","files","but","`","``","foo\/bar\/baz.csv","''","`","would","be","associated","with","partition","`","``","bar","''","`",".","If","the","base","directory","is","undefined",",","then","`","``","foo.csv","''","`","would","be","unpartitioned",",","`","``","foo\/bar.csv","''","`","would","be","associated","with","partition","`","``","foo","''","`",",","and","''","foo\/bar\/baz.csv","''","would","be","associated","with","partition","`","(","``","foo","''",",","``","bar","''",")","`","."]
docstr: Hive partition path parser.
  
  Returns a dictionary mapping partition keys to values given a hive-style
  partition path of the form "{key1}={value1}/{key2}={value2}/..." or an empty
  dictionary for unpartitioned files.
docstr_tok: ["Hive","partition","path","parser",".","Returns","a","dictionary","mapping","partition","keys","to","values","given","a","hive-style","partition","path","of","the","form","``","{","key1","}","=","{","value1","}","\/","{","key2","}","=","{","value2","}","\/","...","''","or","an","empty","dictionary","for","unpartitioned","files","."]
code: def _parse_hive_path(self, dir_path: str) -> Dict[str, str]:
      """Hive partition path parser.
  
      Returns a dictionary mapping partition keys to values given a hive-style
      partition path of the form "{key1}={value1}/{key2}={value2}/..." or an empty
      dictionary for unpartitioned files.
      """
      dirs = [
          d for d in dir_path.split("/") if d and (d.count("=") == 1)
      ]
      kv_pairs = [d.split("=") for d in dirs] if dirs else []
      field_names = self._scheme.field_names
      if field_names and kv_pairs:
          if len(kv_pairs) != len(field_names):
              raise ValueError(
                  f"Expected {len(field_names)} partition value(s) but found "
                  f"{len(kv_pairs)}: {kv_pairs}."
              )
          for i, field_name in enumerate(field_names):
              if kv_pairs[i][0] != field_name:
                  raise ValueError(
                      f"Expected partition key {field_name} but found "
                      f"{kv_pairs[i][0]}"
                  )
      return dict(kv_pairs)
  
imports: import posixpath
  from dataclasses import dataclass
  from enum import Enum
  from typing import TYPE_CHECKING, Callable, Dict, List, Optional
  from ray.util.annotations import DeveloperAPI, PublicAPI
label_desc: Use image node_id 6 for calling the PathPartitionParser obj's underlying member method code with example usage: obj._parse_hive_path(dir_path) and returns: dict