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

Bug: incorrect refactoring - changes functionality #180

Closed
rowlesmr opened this issue Dec 30, 2021 · 0 comments
Closed

Bug: incorrect refactoring - changes functionality #180

rowlesmr opened this issue Dec 30, 2021 · 0 comments
Assignees
Labels
bug Something isn't working next release This will be fixed in next release

Comments

@rowlesmr
Copy link

Issue description or question

Sourcery refactoring changes the function of my block of code. (My code needs refactoring, but sourcery breaks it.)

The issues identified were switch, remove-redundant-if, and remove-pass-elif

I've included the code that was identified by sourcery. There are a few more lines around it, that may or may not be necessary for this bug to occur.

# psuedo-code:
if the plot is not "qpa"
   go through the dictionary and get each dataset
   if the plot is "temp"
      append the temperature data to the list to be plotted
   else if the plot is "pres"
       append the pressure data to the list to be plotted
   plot the list
else
    get the qpa data
    plot the qpa data
# original code
if plot_temp_pres_qpa != "qpa":  # plot_temp_pres_qpa:str == "temp", "pres", or "qpa"
    second_plot = []
    for pattern in self.cif:  # cif is a dictionary defined previously
        cifpat = self.cif[pattern]
        if plot_temp_pres_qpa == "temp":
            try:
                second_plot.append(cifpat["_diffrn_ambient_temperature"])  # append a float
            except KeyError:
                second_plot.append(None)
            ax1.set_xlabel("Temperature (K)")  # ax1 is a Matplotlib Axes defined previously
        elif plot_temp_pres_qpa == "pres":
            try:
                second_plot.append(cifpat["_diffrn_ambient_pressure"])  # append a float
            except KeyError:
                second_plot.append(None)
            ax1.set_xlabel("Pressure (kPa)")
    ax1.plot(second_plot, y, marker="o")  # y is defined previously
else:
    qpa_dict = self.get_all_qpa()
    for phase in qpa_dict:
        ax1.plot(qpa_dict[phase], y, label=phase)
    ax1.set_xlabel("Weight percent (wt%)")
    ax1.legend()

# sourcery code
if plot_temp_pres_qpa == "pres":
    second_plot = []
    for pattern in self.cif:
        cifpat = self.cif[pattern]
    ax1.plot(second_plot, y, marker="o") # if it is "pres", it tries to plot an empty list
elif plot_temp_pres_qpa != "qpa":
    second_plot = []
    for pattern in self.cif:
        cifpat = self.cif[pattern]
        if plot_temp_pres_qpa == "temp":
            try:
                second_plot.append(cifpat["_diffrn_ambient_temperature"])
            except KeyError:
                second_plot.append(None)
            ax1.set_xlabel("Temperature (K)")
            # where is the ax1.plot function call for the temperature data?     
    qpa_dict = self.get_all_qpa()
    for phase in qpa_dict:
        ax1.plot(qpa_dict[phase], y, label=phase)
    ax1.set_xlabel("Weight percent (wt%)")  # why am I plotting qpa data if plot_temp_pres_qpa != "qpa"?
    ax1.legend()

Sourcery Version

0.9.8

Code editor or IDE name and version

Pycharm v2021.3 CE Build #PC-213.5744.248

OS name and version

Windows 10

@Hellebore Hellebore added the bug Something isn't working label Dec 30, 2021
@Hellebore Hellebore self-assigned this Dec 30, 2021
@Hellebore Hellebore added the next release This will be fixed in next release label Dec 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working next release This will be fixed in next release
Projects
None yet
Development

No branches or pull requests

2 participants