p-doom/crowd-code-dataset-0.2 huggingface dataset:
[content] data/jasmine_data/atari/visualize_array_record.py (python)
    # Normalize to bytes
    if isinstance(raw, (bytes, bytearray, memoryview)):
        raw_bytes = bytes(raw)
        try:
            return pickle.loads(raw_bytes)
        except Exception as e:
            raise RuntimeError("Failed to unpickle record bytes") from e
    # If the reader already returns decoded Python objects (e.g., dict)
    if isinstance(raw, dict):
        return raw
    # Try attribute that contains payload
    payload = getattr(raw, "payload", None)
    if isinstance(payload, (bytes, bytearray, memoryview)):
        try:
            return pickle.loads(bytes(payload))
        except Exception as e:
            raise RuntimeError("Failed to unpickle record payload") from e
    raise TypeError("Unsupported record type returned by ArrayRecordReader")
[content] data/jasmine_data/atari/visualize_array_record.py (python)
def _collect_array_record_paths(input_path: str) -> List[str]:
    # Accept a single .array_record file or a directory containing many
    if os.path.isdir(input_path):
        paths: List[str] = []
        for root, _dirs, files in os.walk(input_path):
            for name in files:
                if name.endswith(".array_record"):
                    paths.append(os.path.join(root, name))
        paths.sort()
        if not paths:
            raise FileNotFoundError(
                f"No .array_record files found under directory: {input_path}"
            )
        return paths
    if os.path.isfile(input_path) and input_path.endswith(".array_record"):
        return [input_path]
    raise FileNotFoundError(
        f"Input path must be a directory of .array_record files or a .array_record file: {input_path}"
    )


def _get_num_records(reader: object) -> int:
    try:
        return len(reader)  # type: ignore[arg-type]
    except Exception:
        pass
    # Try common method names
    for name in [
        "count",
        "size",
        "num_records",
        "num_examples",
        "length",
        "num_items",
        "num",
    ]:
        meth = getattr(reader, name, None)
        if callable(meth):
            try:
                val = meth()
                if isinstance(val, int) and val >= 0:
                    return val
            except Exception:
                pass
        elif isinstance(meth, int) and meth >= 0:
            return meth
    raise TypeError("ArrayRecordReader does not expose a record count via len() or known methods")


def _read_record_by_index(reader: object, index: int):
    # Try Python indexing
    try:
        return reader[index]  # type: ignore[index]
    except Exception:
        pass
    # Try common read methods
    for name in ["read", "get", "at"]:
        meth = getattr(reader, name, None)
        if callable(meth):
            try:
                return meth(int(index))
            except Exception:
                pass
    # Batch methods returning a list/sequence
    for name in ["read_by_indices", "read_indices", "get_many", "read_many"]:
        meth = getattr(reader, name, None)
        if callable(meth):
            try:
                batch = meth([int(index)])
                if batch is not None:
                    try:
                        return batch[0]
                    except Exception:
                        pass
            except Exception:
                pass
    raise TypeError("ArrayRecordReader does not support index-based access with known methods")
[content] data/jasmine_data/atari/visualize_array_record.py (python)
    try:
        reader = ArrayRecordReader(paths if len(paths) > 1 else paths[0])
    except Exception:
        # Fallback: some implementations may only accept a single path
        reader = ArrayRecordReader(rng.choice(paths))
    num_records = _get_num_records(reader)
    if num_records <= 0:
[content] data/jasmine_data/atari/visualize_array_record.py (python)
def _collect_array_record_paths(input_path: str) -> List[str]:
    # Accept a single .array_record file or a directory containing many
    if os.path.isdir(input_path):
        paths: List[str] = []
        for root, _dirs, files in os.walk(input_path):
            for name in files:
                if name.endswith(".array_record"):
                    paths.append(os.path.join(root, name))
        paths.sort()
        if not paths:
            raise FileNotFoundError(
                f"No .array_record files found under directory: {input_path}"
            )
        return paths
    if os.path.isfile(input_path) and input_path.endswith(".array_record"):
        return [input_path]
    raise FileNotFoundError(
        f"Input path must be a directory of .array_record files or a .array_record file: {input_path}"
    )


def _get_num_records(reader: Any) -> int:
    try:
        return len(reader)  # type: ignore[arg-type]
    except Exception:
        pass
    # Try common method names
    for name in [
        "count",
        "size",
        "num_records",
        "num_examples",
        "length",
        "num_items",
        "num",
    ]:
        meth = getattr(reader, name, None)
        if callable(meth):
            try:
                val = meth()
                if isinstance(val, int) and val >= 0:
                    return val
            except Exception:
                pass
        elif isinstance(meth, int) and meth >= 0:
            return meth
    raise TypeError("ArrayRecordReader does not expose a record count via len() or known methods")


def _read_record_by_index(reader: Any, index: int):
    # Try Python indexing
    try:
        return reader[index]  # type: ignore[index]
    except Exception:
        pass
    # Try common read methods
    for name in ["read", "get", "at"]:
        meth = getattr(reader, name, None)
        if callable(meth):
            try:
                return meth(int(index))
            except Exception:
                pass
    # Batch methods returning a list/sequence
    for name in ["read_by_indices", "read_indices", "get_many", "read_many"]:
        meth = getattr(reader, name, None)
        if callable(meth):
            try:
                batch = meth([int(index)])
                if batch is not None:
                    try:
                        return batch[0]
                    except Exception:
                        pass
            except Exception:
                pass
    raise TypeError("ArrayRecordReader does not support index-based access with known methods")
[content] data/jasmine_data/atari/visualize_array_record.py (python)
def _collect_array_record_paths(input_path: str) -> List[str]:
    # Accept a single .array_record file or a directory containing many
    if os.path.isdir(input_path):
        paths: List[str] = []
        for root, _dirs, files in os.walk(input_path):
            for name in files:
                if name.endswith(".array_record"):
                    paths.append(os.path.join(root, name))
        paths.sort()
        if not paths:
            raise FileNotFoundError(
                f"No .array_record files found under directory: {input_path}"
            )
        return paths
    if os.path.isfile(input_path) and input_path.endswith(".array_record"):
        return [input_path]
    raise FileNotFoundError(
        f"Input path must be a directory of .array_record files or a .array_record file: {input_path}"
    )


def _get_num_records(reader: Any) -> int:
    try:
        return len(reader)  # type: ignore[arg-type]
    except Exception:
        pass
    # Try common method names
    for name in [
        "count",
        "size",
        "num_records",
        "num_examples",
        "length",
        "num_items",
        "num",
    ]:
        meth = getattr(reader, name, None)
        if callable(meth):
            try:
                val = meth()
                if isinstance(val, int) and val >= 0:
                    return val
            except Exception:
                pass
        elif isinstance(meth, int) and meth >= 0:
            return meth
    raise TypeError("ArrayRecordReader does not expose a record count via len() or known methods")


def _read_record_by_index(reader: Any, index: int):
    # Try Python indexing via __getitem__ to avoid static typing issues
    getitem = getattr(reader, "__getitem__", None)
    if callable(getitem):
        try:
            return getitem(int(index))
        except Exception:
            pass
    # Try common read methods
    for name in ["read", "get", "at"]:
        meth = getattr(reader, name, None)
        if callable(meth):
            try:
                return meth(int(index))
            except Exception:
                pass
    # Batch methods returning a list/sequence
    for name in ["read_by_indices", "read_indices", "get_many", "read_many"]:
        meth = getattr(reader, name, None)
        if callable(meth):
            try:
                batch = meth([int(index)])
                if batch is not None:
                    try:
                        return batch[0]
                    except Exception:
                        pass
            except Exception:
                pass
    raise TypeError("ArrayRecordReader does not support index-based access with known methods")
[content] data/jasmine_data/atari/visualize_array_record.py (python)
def _collect_array_record_paths(input_path: str) -> List[str]:
    # Accept a single .array_record file or a directory containing many
    if os.path.isdir(input_path):
        paths: List[str] = []
        for root, _dirs, files in os.walk(input_path):
            for name in files:
                if name.endswith(".array_record"):
                    paths.append(os.path.join(root, name))
        paths.sort()
        if not paths:
            raise FileNotFoundError(
                f"No .array_record files found under directory: {input_path}"
            )
        return paths
    if os.path.isfile(input_path) and input_path.endswith(".array_record"):
        return [input_path]
    raise FileNotFoundError(
        f"Input path must be a directory of .array_record files or a .array_record file: {input_path}"
    )


def _get_num_records(reader: Any) -> int:
    try:
        return len(reader)  # type: ignore[arg-type]
    except Exception:
        pass
    # Try common method names
    for name in [
        "count",
        "size",
        "num_records",
        "num_examples",
        "length",
        "num_items",
        "num",
    ]:
        meth = getattr(reader, name, None)
        if callable(meth):
            try:
                val = meth()
                if isinstance(val, int) and val >= 0:
                    return val
            except Exception:
                pass
        elif isinstance(meth, int) and meth >= 0:
            return meth
    raise TypeError("ArrayRecordReader does not expose a record count via len() or known methods")


def _read_record_by_index(reader: Any, index: int):
    # Try Python indexing via __getitem__ to avoid static typing issues
    getitem = getattr(reader, "__getitem__", None)
    if callable(getitem):
        try:
            return getitem(int(index))
        except Exception:
            pass
    # Try common read methods
    for name in ["read", "get", "at"]:
        meth = getattr(reader, name, None)
        if callable(meth):
            try:
                return meth(int(index))
            except Exception:
                pass
    # Batch methods returning a list/sequence
    for name in ["read_by_indices", "read_indices", "get_many", "read_many"]:
        meth = getattr(reader, name, None)
        if callable(meth):
            try:
                batch = meth([int(index)])
                if batch is not None:
                    try:
                        iterator = iter(batch)
                        return next(iterator)
                    except Exception:
                        pass
            except Exception:
                pass
    raise TypeError("ArrayRecordReader does not support index-based access with known methods")
[content] data/jasmine_data/atari/visualize_array_record.py (python)
def _collect_array_record_paths(input_path: str) -> List[str]:
    # Accept a single .array_record file or a directory containing many
    if os.path.isdir(input_path):
        paths: List[str] = []
        for root, _dirs, files in os.walk(input_path):
            for name in files:
                if name.endswith(".array_record"):
                    paths.append(os.path.join(root, name))
        paths.sort()
        if not paths:
            raise FileNotFoundError(
                f"No .array_record files found under directory: {input_path}"
            )
        return paths
    if os.path.isfile(input_path) and input_path.endswith(".array_record"):
        return [input_path]
    raise FileNotFoundError(
        f"Input path must be a directory of .array_record files or a .array_record file: {input_path}"
    )


def _get_num_records(reader: Any) -> int:
    try:
        return len(reader)  # type: ignore[arg-type]
    except Exception:
        pass
    # Try common method names
    for name in [
        "count",
        "size",
        "num_records",
        "num_examples",
        "length",
        "num_items",
        "num",
    ]:
        meth = getattr(reader, name, None)
        if callable(meth):
            try:
                val = meth()
                if isinstance(val, int) and val >= 0:
                    return val
            except Exception:
                pass
        elif isinstance(meth, int) and meth >= 0:
            return meth
    raise TypeError("ArrayRecordReader does not expose a record count via len() or known methods")


def _read_record_by_index(reader: Any, index: int):
    # Try Python indexing via __getitem__ to avoid static typing issues
    getitem = getattr(reader, "__getitem__", None)
    if callable(getitem):
        try:
            return getitem(int(index))
        except Exception:
            pass
    # Try common read methods
    for name in ["read", "get", "at"]:
        meth = getattr(reader, name, None)
        if callable(meth):
            try:
                return meth(int(index))
            except Exception:
                pass
    # Batch methods returning a list/sequence
    for name in ["read_by_indices", "read_indices", "get_many", "read_many"]:
        meth = getattr(reader, name, None)
        if callable(meth):
            try:
                batch = meth([int(index)])
                if batch is not None:
                    try:
                        first = cast(Any, batch)[0]
                        return first
                    except Exception:
                        pass
            except Exception:
                pass
    raise TypeError("ArrayRecordReader does not support index-based access with known methods")