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

Remove deprecated setter methods on Frequency #878

Merged
merged 3 commits into from
May 25, 2023

Conversation

eendebakpt
Copy link
Contributor

@eendebakpt eendebakpt commented Apr 4, 2023

Remove two deprecated setter methods on the Frequency object.

Note: the Frequency object is now mostly immutable except for the unit and a few public methods (e.g. round_to).

@FranzForstmayr
Copy link
Collaborator

Do we need the unit to be mutable?

@jhillairet
Copy link
Member

Do we need the unit to be mutable?

I think yes. Often the unit is set in Hz and one would like to change to MHz/GHz to get nice plot tick axis labels.

@FranzForstmayr
Copy link
Collaborator

Ok, this is the unit for representation. The underlying frequency vector stays the same after change which is fine.

@FranzForstmayr
Copy link
Collaborator

We've still the round_to method which writes the f vector. Is this covered by any test? I don't think this should work after this change....

In addition the drop_non_monotonic_increasing method writes self._f. I'm not sure how we should handle this, when the frequency vector should be immutable?

@cafeclimber
Copy link
Contributor

Could it just return a new Frequency with those updated values?

@eendebakpt
Copy link
Contributor Author

The tests pass because the frequencies are constructed using Frequency.from_f which modifies the _f and reverts the writable flag. If we add the writable flag there, the test for drop_non_monotonic_increasing will fail.

We can modify the drop_non_monotonic_increasing on the Frequency object, but not in a backwards compatible way (currently it modifies the Frequency inplace and returns the list of invalid indices).

The case of round_to is similar: making the Frequency._f read-only will break the round_to.

@eendebakpt
Copy link
Contributor Author

I will remove the self._f.setflags(write = False) from this PR, it would break existing code without any deprecation warnings.

We could add deprecation warnings to the methods that modify the Frequency (e.g. the .f setter, round_to, drop_non_monotonic_increasing) and provide alternatives that work with an immutable Frequency, but I am not the one to decide on this.

@eendebakpt eendebakpt changed the title Draft: make Frequency immutable Remove setter methods on Frequency Apr 6, 2023
@jhillairet jhillairet self-requested a review April 10, 2023 19:29
@jhillairet
Copy link
Member

jhillairet commented Apr 10, 2023

We could add deprecation warnings to the methods that modify the Frequency (e.g. the .f setter, round_to, drop_non_monotonic_increasing) and provide alternatives that work with an immutable Frequency, but I am not the one to decide on this.

I think it is a good idea to add a deprecation warning.

Then make Frequency immutable for version 1.0 ?

@eendebakpt
Copy link
Contributor Author

We could add deprecation warnings to the methods that modify the Frequency (e.g. the .f setter, round_to, drop_non_monotonic_increasing) and provide alternatives that work with an immutable Frequency, but I am not the one to decide on this.

I think it is a good idea to add a deprecation warning.

Then make Frequency immutable for version 1.0 ?

What will we do with the unit? It is not only used in representation methods, but also in computations. For example the Network,__getitem__ or Frequency.overlap_freq. (see comment #878 (comment))
Making the Frequency immutable means making the .unit fixed, or also deprecating methods that use the unit for computations.

We can deprecate the round_to, but should also provide alternatives. The original methods are inplace, so the best option seems to be to provide non-inplace alternatives with a different name, e.g.

def round_to_precision(self, val: Union[str, Number] = 'hz') -> Frequency:

@jhillairet
Copy link
Member

Making the Frequency immutable means making the .unit fixed, or also deprecating methods that use the unit for computations.

Good question. Personaly, I often have to change the unit to get nicer print or plot. So I think a way to change the unit is needed, but I'm biased.

@jhillairet
Copy link
Member

anyone else's advice? What should we do with this?

skrf/frequency.py Outdated Show resolved Hide resolved
@jhillairet jhillairet marked this pull request as draft May 10, 2023 06:16
@eendebakpt
Copy link
Contributor Author

anyone else's advice? What should we do with this?

@jhillairet I updated the description of the PR to remove deprecated setter methods. The unit is left unchanged, I think this is best done in another PR (if there is consensus on how to move forward).

@eendebakpt eendebakpt changed the title Remove setter methods on Frequency Remove deprecated setter methods on Frequency May 20, 2023
@jhillairet jhillairet marked this pull request as ready for review May 21, 2023 07:45
@jhillairet jhillairet merged commit 766a757 into scikit-rf:master May 25, 2023
10 checks passed
@jhillairet jhillairet mentioned this pull request Jun 26, 2023
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.

None yet

4 participants