Skip to content

Crash if trying to read register with no data #54

@ablot

Description

@ablot

If I have a behaviour box and do a recording where the output valve was never triggered, the OutputSet register is empty and the corresponding file (Behavior_34.bin) is empty.

Trying to access the register (to check if there is any event) returns a cryptic "KeyError"

Code:

import harp as harp_pkg

reader = harp_pkg.create_reader(harp_folder)
reward_messages = reader.OutputSet.read()

Error:

  File "/nemo/lab/znamenskiyp/home/users/blota/code/cottage_analysis/cottage_analysis/io_module/harp.py", line 547, in read_from_binaries
    reward_messages = reader.OutputSet.read()
  File "/nemo/lab/znamenskiyp/home/users/blota/code/harp-python/harp/reader.py", line 91, in parser
    result = f(df)
  File "/nemo/lab/znamenskiyp/home/users/blota/code/harp-python/harp/reader.py", line 111, in parser
    return DataFrame({n: f(df[0]) for n, f in lookup}, index=df.index)
                           ~~^^^
  File "/camp/home/blota/.conda/envs/onix-3dvision/lib/python3.13/site-packages/pandas/core/frame.py", line 4113, in __getitem__
    indexer = self.columns.get_loc(key)
  File "/camp/home/blota/.conda/envs/onix-3dvision/lib/python3.13/site-packages/pandas/core/indexes/range.py", line 415, in get_loc
    raise KeyError(key) from err
KeyError: 0

Suggestion: if the output from np.fromfile is empty, return an empty dataframe

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions