[Feature]: Implement indexable properties for Collection attributes using the descriptor protocol
- Dominant language
- Python
- Stars
- 42
- Forks
- 18
- Avg merge
- 1m
- Merged PRs (30d)
- 1
Description
Currently, many properties in our codebase return complete DataFrames (e.g., `AgentSetDF.agents`, `Grid.cells`, etc.). While useful, this approach lacks flexibility when users need to access specific subsets of data.
Proposed Enhancement:
Implement indexable properties that support masking, allowing more granular data access. This would enable syntax like `AgentSetDF.agents[ids]` or `Grid.cells[coords]`.
Implementation Details:
1. Utilize the [descriptor protocol](https://docs.python.org/3/howto/descriptor.html) to maintain the current behavior when accessing the full property, while adding support for indexing and masking.
2. Ensure that the `__getitem__` method of the descriptor returns a DataFrame subset when a mask is provided.
3. Implement a setter method to allow operations like `Grid.cells[coords] = properties`, enhancing API usability.
Benefits:
- More intuitive and flexible data access
- Improved code readability and efficiency when working with subsets of data
- Consistent API across different components of the library
Example Usage:
```python
# Current: Returns full DataFrame
all_agents = agent_set.agents
# Proposed: Returns subset of agents
specific_agents = agent_set.agents[specific_ids]
# Proposed: Set properties for specific cells
grid.cells[specific_coords] = new_properties
```
Contributor guide
Research direction
Start by locating the implementations of AgentSetDF.agents and Grid.cells, then review Python's descriptor protocol documentation. Define how full-property access, masking through __getitem__, and assignment through the setter should behave for both examples. Done means indexed reads return the intended DataFrame subsets and indexed writes update selected properties without breaking existing full-property access.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- pandas, python
- Domain
- api, data
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100