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

Deprecate Diffraction_object, rename to DiffractionObject #165

Closed
wants to merge 12 commits into from

Conversation

bobleesj
Copy link
Contributor

@bobleesj bobleesj commented Nov 9, 2024

No description provided.

Copy link
Contributor Author

@bobleesj bobleesj Nov 9, 2024

Choose a reason for hiding this comment

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

Two deprecation messages written 1) docstring level 2) class level

@@ -18,6 +19,20 @@


class Diffraction_object:
"""FIXME: Add class docstring.

.. deprecated:: 3.5.1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Following the numpy deprecation standards:

Screenshot 2024-11-09 at 12 28 11 PM

Ref: https://numpydoc.readthedocs.io/en/latest/format.html#deprecation-warning

Copy link

codecov bot commented Nov 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.27%. Comparing base (2559946) to head (7c73140).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #165      +/-   ##
==========================================
+ Coverage   99.17%   99.27%   +0.09%     
==========================================
  Files           7        8       +1     
  Lines         243      274      +31     
==========================================
+ Hits          241      272      +31     
  Misses          2        2              
Files with missing lines Coverage Δ
tests/test_diffraction_object.py 100.00% <100.00%> (ø)

`DiffractionObject` to follow the class naming convention.
"""

warnings.warn(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Warning produced at the run-time level:

Screenshot 2024-11-09 at 12 29 11 PM

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks good. Here I would maybe begin with the words "Diffraction_object is deprecated and will be removed....."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor Author

@bobleesj bobleesj left a comment

Choose a reason for hiding this comment

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

Ready for review - learning how to handle deprecation more gracefully in our group.

@bobleesj bobleesj marked this pull request as ready for review November 9, 2024 17:31
@sbillinge
Copy link
Contributor

We also need the new class and it's tests. I guess it makes sense to have it on the same PR?

@bobleesj bobleesj mentioned this pull request Nov 10, 2024
12 tasks
@bobleesj bobleesj changed the title Diffraction_object deprecation warning - discussions needed Deprecate Diffraction_object, rename to DiffractionObject Nov 10, 2024
@@ -26,3 +26,12 @@ diffpy.utils.scattering_objects.diffraction_objects module
:members:
:undoc-members:
:show-inheritance:


diffpy.utils.scattering_objects.diffraction_object module
Copy link
Contributor Author

Choose a reason for hiding this comment

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

API module created for DiffractionObject

@@ -0,0 +1,265 @@
from pathlib import Path
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same comment above - new file since file name changed



class DiffractionObject:
"""
Copy link
Contributor Author

@bobleesj bobleesj Nov 10, 2024

Choose a reason for hiding this comment

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

I included docstrings for this class. Initially, I also created docstrings for each method within this class docstring above __init__. However, when I rendered the documentation locally, I noticed duplicate entries, as the docstring for each method is provided already. Therefore, here, I’ve only included descriptions for the Parameters and Aattributes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this PR, none was modified except the class name.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. So this is a direct copy-paste to duplicate it and then change the name, so we have both and they are identical to each other?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, they are identical, direct copy.

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case maybe let's keep it that way and not make any changes, just the name change?

@bobleesj
Copy link
Contributor Author

@sbillinge Ready for review, a few comments added via inline. Thank you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

File name has been changed from diffraction_objects to diffraction_object which carries DiffractionObject

Copy link
Contributor

Choose a reason for hiding this comment

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

why is the filename changed? This would lead to an API change if we add an additional diffraction object in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

using one class per file seems to be a modular approach. And considering this file is located under the scattering_objects directory, we could add additional classes as separate files.

Copy link
Contributor

Choose a reason for hiding this comment

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

doesn't this just add useless typing though?

from diffpy.utils.scattering_objects.diffraction_object import DiffractionObject
from diffpy.utils.scattering_objects.pdf_object import PdfObject 
...

The point of the current structure is that all diffraction objects go in the diffraction_objects module. What is the advantage of putting one per module?

Copy link
Contributor Author

@bobleesj bobleesj Nov 13, 2024

Choose a reason for hiding this comment

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

For the useless typing, if we could utilize relative import, would this be a good solution below?

from diffpy.utils.scattering import DiffractionObject
from diffpy.utils.scattering import PdfObject

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also not sure if we want to call it as "Object" since we are utilizing a class and object is something we make with the class..

from diffpy.utils.scattering import Diffraction
from diffpy.utils.scattering import Pdf

This a bit more feels like pythonic?

Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't quite convey what it does though. Diffraction is a method, a DiffractionObject is the result of a diffraction experiment. We could call it DiffractionDataset or something. I kind of like DiffractionObject though.

I thought the task was to bring the current naming more into PEP8 standard, not to do a refactor?

Copy link
Contributor

@sbillinge sbillinge left a comment

Choose a reason for hiding this comment

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

few comments. Also, please check if there were tests for Diffraction_object. If there were, we should leave them until Diffraction_object is removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

why is the filename changed? This would lead to an API change if we add an additional diffraction object in the future.

class DiffractionObject:
"""
A class to manipulate diffraction data, supporting basic arithmetic operations and
conversions between different diffraction data metrics such as Q, two-theta, and d-spacing.
Copy link
Contributor

Choose a reason for hiding this comment

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

change metrics here to independent variables?


Parameters
----------
name : str, optional
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the difference between a parameter and an attribute here?

Also, per numpy standards, desriptions always start with "The" so wavelength would be "The wavelength of the radiation used in the diffraction experiment. Defaults to None." which, slightly magically, makes everything much more readable. Please change everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is the difference between a parameter and an attribute here?

Fixed. Consistent now.

scat_quantity : str
Description of the type of scattering data stored.
on_q : list of numpy.ndarray
A list containing two numpy arrays: [Q values, Intensities].
Copy link
Contributor

Choose a reason for hiding this comment

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

The "the" constructions helps with these docstrings here, because we need a short statement of what this is, which is missing. In this case it could be "The diffraction intensities on a grid of Q" followed by something along the ines you already put (i.e., high level view followed by pertinent details).


def set_qs_from_range(self, begin_q, end_q, step_size=None, n_steps=None):
"""
create an array of linear spaced Q-values
Copy link
Contributor

Choose a reason for hiding this comment

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

linearly

----------
begin_q float
the beginning angle
end_q float
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we usually have colons here end_q: float

@bobleesj
Copy link
Contributor Author

few comments. Also, please check if there were tests for Diffraction_object. If there were, we should leave them until Diffraction_object is removed.

Thanks for the feedback I will address each in the afternoon.

Copy link
Contributor

@sbillinge sbillinge left a comment

Choose a reason for hiding this comment

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

pls see discussion comments.

Copy link
Contributor

Choose a reason for hiding this comment

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

doesn't this just add useless typing though?

from diffpy.utils.scattering_objects.diffraction_object import DiffractionObject
from diffpy.utils.scattering_objects.pdf_object import PdfObject 
...

The point of the current structure is that all diffraction objects go in the diffraction_objects module. What is the advantage of putting one per module?



class DiffractionObject:
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

I see. So this is a direct copy-paste to duplicate it and then change the name, so we have both and they are identical to each other?

Copy link
Contributor Author

@bobleesj bobleesj left a comment

Choose a reason for hiding this comment

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

@sbillinge ready for review again. Thank you.

Copy link
Contributor

@sbillinge sbillinge left a comment

Choose a reason for hiding this comment

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

Please see comments. I think we are trying to do a bit too much of a refactor here. I suggest we just do the name-change and the deprecation warnings.

If we want to remove extra typing we could simply put DiffractionObject into scattering_objects.py module. This might make more sense.

In the future I expect we might have a PdfObject, but also others in principle, like XanesObject, RamanObject, and so on.

Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't quite convey what it does though. Diffraction is a method, a DiffractionObject is the result of a diffraction experiment. We could call it DiffractionDataset or something. I kind of like DiffractionObject though.

I thought the task was to bring the current naming more into PEP8 standard, not to do a refactor?



class DiffractionObject:
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

In that case maybe let's keep it that way and not make any changes, just the name change?

@bobleesj
Copy link
Contributor Author

Please see comments. I think we are trying to do a bit too much of a refactor here. I suggest we just do the name-change and the deprecation warnings.

If we want to remove extra typing we could simply put DiffractionObject into scattering_objects.py module. This might make more sense.

In the future I expect we might have a PdfObject, but also others in principle, like XanesObject, RamanObject, and so on.

Yes, too much refactoring I agree (good discussions still It think). I created a new PR below, just focused on changing the name and deprecating it.

#172

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.

2 participants