Skip to content

Return custom objects that implements Sequence protocol, from fetch_capture_waveform()#1430

Closed
sbethur wants to merge 1 commit intomasterfrom
bug1389/nidigital_custom_capture_waveform_type
Closed

Return custom objects that implements Sequence protocol, from fetch_capture_waveform()#1430
sbethur wants to merge 1 commit intomasterfrom
bug1389/nidigital_custom_capture_waveform_type

Conversation

@sbethur
Copy link
Copy Markdown
Contributor

@sbethur sbethur commented Apr 23, 2020

  • This contribution adheres to CONTRIBUTING.md.

  • I've updated CHANGELOG.md if applicable.

  • I've added tests applicable for this pull request

What does this Pull Request accomplish?

  • Add a custom class - CaptureWaveform to implements collections.abc.Sequence interface
  • Update fetch_capture_waveform() to return CaptureWaveform objects in the dictionary

Note: The PR is not complete. I'm creating a draft version to get some initial feedback before spending more time on it. The following items have not been done yet:

  • Add necessary tests
  • Update documentation
  • Update CHANGELOG

List issues fixed by this Pull Request below, if any.

What testing has been done?

New tests added. CI will run all tests.

@sbethur sbethur requested a review from marcoskirsch April 23, 2020 19:43
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 23, 2020

Codecov Report

Merging #1430 into master will increase coverage by 0.00%.
The diff coverage is 80.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #1430     +/-   ##
=========================================
  Coverage   91.90%   91.90%             
=========================================
  Files          20       32     +12     
  Lines        3642     7008   +3366     
=========================================
+ Hits         3347     6441   +3094     
- Misses        295      567    +272     
Flag Coverage Δ
#codegenunittests 88.24% <ø> (ø)
#nidcpowersystemtests 98.58% <ø> (?)
#nidigitalsystemtests 84.48% <80.00%> (?)
#nidmmsystemtests 95.48% <ø> (?)
#nifakeunittests 96.36% <ø> (ø)
#nifgensystemtests 96.91% <ø> (?)
#nimodinstsystemtests 87.23% <ø> (?)
#nimodinstunittests 95.37% <ø> (ø)
#niscopesystemtests 83.15% <ø> (?)
#nisesystemtests 100.00% <ø> (?)
#niswitchsystemtests 98.11% <ø> (?)
#nitclksystemtests 100.00% <ø> (?)
#nitclkunittests 95.45% <ø> (ø)
Impacted Files Coverage Δ
generated/nidigital/nidigital/capture_waveform.py 78.57% <78.57%> (ø)
generated/nidigital/nidigital/_library.py 83.89% <100.00%> (ø)
generated/nidmm/nidmm/_library.py 95.48% <0.00%> (ø)
generated/nise/nise/_library.py 100.00% <0.00%> (ø)
generated/niswitch/niswitch/_library.py 98.11% <0.00%> (ø)
generated/nimodinst/nimodinst/_library.py 87.23% <0.00%> (ø)
...digital/nidigital/history_ram_cycle_information.py 100.00% <0.00%> (ø)
generated/nitclk/nitclk/_library.py 100.00% <0.00%> (ø)
generated/nidcpower/nidcpower/_library.py 98.58% <0.00%> (ø)
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 05fee0c...4b6f3fd. Read the comment docs.

Comment thread generated/nidigital/nidigital/__init__.py
Comment thread generated/nidigital/nidigital/_library.py
self._capture_waveform_data = capture_waveform_data

def __repr__(self):
return str(self)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From https://docs.python.org/3.4/reference/datamodel.html#object.__repr__

If at all possible, this should look like a valid Python expression that could be used to recreate an object with the same value (given an appropriate environment).

Usually this means You'll want the __module__ and __qualname__ of the class in there along with the args.

E.g.

def __repr__(self):
   return "{}.{}({})".format(self.__class__.__module__, self.__class__.__qualname__, ...)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually this means You'll want the module and qualname of the class in there along with the args.

This is good to know. I couldn't find any best practice tips for __repr__ online. I checked a couple of popular external libraries and didn't find them including __module__:

>>> import numpy as np
>>> n = np.arange(2)
>>> repr(n)
'array([0, 1])'

>>> import pandas as pd
>>> t = pd.CategoricalDtype(categories=['b', 'a'], ordered=True)
>>> repr(t)
"CategoricalDtype(categories=['b', 'a'], ordered=True)"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at internal libraries, as they're probably the best citizens:

>>>import datetime
>>> datetime.datetime(1, 2, 3)
datetime.datetime(1, 2, 3, 0, 0)
>>> import operator
>>> operator.attrgetter("foo")
operator.attrgetter('foo')

Although that's not consistent either:

>>> import collections
>>> collections.OrderedDict()
OrderedDict()

🤷‍♂️ Since you're defining this same type in several libraries, it might be good to tell the user which library it came from.

class CaptureWaveform(collections.abc.Sequence):
'''Used by fetch_capture_waveform() to return the capture waveform data'''
def __init__(self, capture_waveform_data):
self._capture_waveform_data = capture_waveform_data
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class is already named "CaptureWaveform", so having the argument and attribute also have "capture waveform" in it is superfluous.

@sbethur
Copy link
Copy Markdown
Contributor Author

sbethur commented Apr 24, 2020

PR rejected. See here for details.

@sbethur sbethur closed this Apr 24, 2020
@sbethur sbethur deleted the bug1389/nidigital_custom_capture_waveform_type branch April 24, 2020 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide string representation for data returned by fetch_capture_waveform() in nidigital

2 participants