Skip to content

Commit

Permalink
Merge pull request #1070 from wright-group/ipython-repr
Browse files Browse the repository at this point in the history
ipython integration: autocompletion
  • Loading branch information
kameyer226 committed Jun 14, 2022
2 parents a968c37 + 767bb9d commit 2fecf16
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).

## [Unreleased]

## Added
- iPython integration: autocomplete includes axis, variable, and channel names

### Fixed
- `kit.fft`: fixed bug where Fourier coefficients were off by a scalar factor.

Expand Down
7 changes: 7 additions & 0 deletions WrightTools/collection/_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ def __repr__(self):
self.natural_name, self.item_names, "::".join([self.filepath, self.name])
)

def __dir__(self) -> list:
default = object.__dir__(self)
return default + list(self._ipython_key_completions_())

def _ipython_key_completions_(self) -> list:
return list(self.item_names)

def __getitem__(self, key):
if isinstance(key, int):
key = self.item_names[key]
Expand Down
10 changes: 10 additions & 0 deletions WrightTools/data/_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ def __repr__(self) -> str:
self.natural_name, str(self.axis_names), "::".join([self.filepath, self.name])
)

def __dir__(self) -> list:
default = object.__dir__(self)
axes = [ax.natural_name for ax in self.axes]
return default + axes + self._ipython_key_completions_()

def _ipython_key_completions_(self) -> list:
channels = [ch.natural_name for ch in self.channels]
variables = [v.natural_name for v in self.variables]
return channels + variables

@property
def axes(self) -> tuple:
return tuple(self._axes)
Expand Down

0 comments on commit 2fecf16

Please sign in to comment.