Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typing module Unit-Tests, some new features and refactor typing code #22

Merged
merged 26 commits into from
Mar 23, 2024

Conversation

armando-palacio
Copy link
Owner

@armando-palacio armando-palacio commented Mar 19, 2024

🚀 Bump version to v1.0.0

✨ Features:

On Binary Sequence:

  • Add scalar support (a665f72)
    >>> binary_sequence(1)
    binary_sequence([1])

On Electrical Signal

  • Add __repr__ method and improve printing style. If noise is zeros array it is not printed.
    >>> electrical_signal([1,2,3,4], [0,0,0,0])
    electrical_signal([1 2 3 4])
  • signal and noise keep type of input arrays (before it were set as complex).
  • Now accept strings as inputs.
    >>> electrical_signal('1,2,3,4', '0 0.1 0.3 -0.1')
    electrical_signal(signal=[1. 2. 3. 4.],
                       noise=[ 0.   0.1  0.3 -0.1])
  • Scalars values are accepted now as input
  • Add support for substact -. Can substracct an int, str, iterable, electrical_signal.
    >>> electrical_signal('1 2 3 4') - 1
    electrical_signal([0 1 2 3])
    >>> electrical_signal('1 2 3 4') - '1 1 2 2j'
    electrical_signal([0.+0.j 1.+0.j 1.+0.j 4.-2.j])
  • Add a new parameter hold=True in plot and psd methods to manage if create or not a new figure.
  • phase function now calculate phase of signal + noise (before only signal).

On Optical Signal

  • Scalar inputs are now supported.
  • Can drive 1 or 2 polarizations now (new attribute n_pol was added). If 1 polarization, signal and noise arrays will have shapes (N,). If 2 polarizations, signal and noise will have shapes (2,N). Number of polarizations are detected automatically from inputs shapes or can be forced by n_pol argument.
    >>> optical_signal([[1,2,3,4]])  # automatically detect 2 polarizations
    optical_signal([[1 2 3 4]
                    [1 2 3 4]])
    >>> optical_signal([[1,2,3,4]], n_pol=1)  # force 1 polarization
    optical_signal([1 2 3 4])
  • phase function now calculate phase of signal + noise (before only signal).
  • power, abs and __call__ functions now accept capital letters as inputs.
  • signal and noise keep type of input arrays (before it were set as complex).
  • Now accept strings as inputs.
  • Add support for substact -. Can substracct an int, str, iterable, optical_signal.
  • Add a new parameter hold=True in plot and psd methods to manage if create or not a new figure.

Others

  • utils.str2array enhancement. This function now autodetect the output array type from string format if dtype is not given. Support more than one row, using semicolon ; to separate the rows. Support complex output type.
    >>> str2array('1 2 3 4')  # type int
    array([1, 2, 3, 4])
    >>> str2array('1.1 2.2 3.3 4.4')  # type float
    array([1.1, 2.2, 3.3, 4.4])
    >>> str2array('101001')  # type bool
    array([ True, False,  True, False, False,  True])  
    >>> str2array('1 2 3 4+2j')  # type complex
    array([1.+0.j, 2.+0.j, 3.+0.j, 4.+2.j])
    >>> str2array('1 2 3 4; 5 6 7 8')  # more than one raw
    array([[1, 2, 3, 4],
           [5, 6, 7, 8]])
    >>> str2array('1+3j 2+4j 3+5j 4+6j', dtype=int)  # can force a type
    array([1, 2, 3, 4])

🧪 Tests:

  • Added unittest for global_variables
  • Added unittest for binary_sequence
  • Added unittest for electrical_signal
  • Added unittest for optical_signal
  • Added unittest for eye

🐛 Bugs:

  • fix a bug in electrical_signal.__lt__, operator < was inverted.
  • reforze inizilization functions of objects.
  • add a check for same length in __add__, __sub__, __rsub__, __mul__, __gt__ and __lt__.
  • fix eye calculation error of devices.GET_EYE when there are not enough data to estimate the cross time. Default values were set when this happend (t_left=-0.5, t_right=0.5 and t_center=0).

💥 BREAKING CHANGE

  • Update python requirements to >=3.10 in order to express arguments type separated by | instead of use Union[]

⚠️ An error is raised when an array is added or substracted from left #23.

- change some TypeError by ValueError
- add `__repr__` method
- fix a bug in `__lt__`, operator `<` was inverted.
- `phase` function now calculate phase of signal + noise (before only signal).
- add `lower()` attribute to `by` parameter in `power` and `abs` functions to accept capitalization.
@armando-palacio armando-palacio self-assigned this Mar 19, 2024
@armando-palacio armando-palacio added bug Something isn't working tests For changes related to unittest of package refactor For changes on code that not modify its functionality new feature For new Features labels Mar 19, 2024
… and add __repr__ method to optical_signal class
I make this to be able to express arguments type separated by `|` instead of use `Union[]`, and this feature is available from python version `3.10` onwards.
- Now import opticomlib as `op`.
- change release variable for version variable.
1. this function now autodetect the output array type from string format if dtype is not given.
2. now support more than one row, using semicolon `;` to separate the rows.
3. now support `complex` output type.
general: change `Union[]` to `|` in argument types.

- on `binary_sequence`
  1. refactor type accepted in __init__
  2. fix raises for check correct format of data in __init__
  3. fix check format when __add__ or __radd__.

- on `electrical_signal`
  1. new feature, now accept `strings` as inputs.
  2. delete special functions from autosummary in class docstring
  3. add some notes to __init__ docstring.
  4. reforze input format checks.
  5. improve the printing style

- on `optical_signal`
  1. same changes than `electrical_signal` because of optical_signal is a children of electrical_signal.
- now `signal` and `noise` in this objects keep type of input arrays.
- upgrade `__repr__` to hide `noise` when it have all zeros.
- fix: add a check for same length in `__add__`, `__sub__`, `__rsub__`, `__mul__`, `__gt__` and `__lt__`
- fix: add a check for dimensions in `opticomlib.__init__`.
1. scalar values are accepted now as inputs
2. `abs` and `__call__` methods now accept capitalized inputs too.
3. `optical_signal` can drive 1 or 2 polarizations now (new attribute `n_pol` was added). If 1 polarization, signal and noise arrays will have shapes (N,). If 2 polarizations, signal and noise will have shapes (2,N). Number of polarizations are detected automatically from inputs shapes or can be forced by `n_pol` argument.
4. Add support for substract, implementing __sub__ and __rsub__.

style: style of objects representation was retouched.

Some methods were also reworked to ensure compatibility with the new features introduced (__init__, __repr__, len, __add__, __mul__, __getitem__, plot, psd)
new test cases and code refactors was made on electical_signal too.
…open a new figure or not.

refact: refactor of eye code
…stimate the cross time. Default values were set when this happend
fix wrong cases on gt_and_lt in electrical_signal and set all hold=False in plots
@armando-palacio armando-palacio merged commit 0d2f697 into main Mar 23, 2024
3 checks passed
@armando-palacio armando-palacio deleted the test/typing branch March 23, 2024 03:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working new feature For new Features refactor For changes on code that not modify its functionality tests For changes related to unittest of package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant