internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: wright-group/WrightTools

Issue:
Some methods of data attempt to set attributes using old 'z' nomenclature. 
For instance,  [`data.level()`](https://github.com/wright-group/WrightTools/blob/development/WrightTools/data.py#L1045-L1047).

I notice that `data.dOD()`, and `data.from_KENT()` also attempt to set these attributes. 


Discussion:

Resolving patch:
diff --git a/WrightTools/data.py b/WrightTools/data.py
--- a/WrightTools/data.py
+++ b/WrightTools/data.py
@@ -822,7 +822,7 @@ def dOD(self, signal_channel, reference_channel,
         # finish
         self.channels[signal_channel_index].give_values(out)
         self.channels[signal_channel_index].signed = True
-        self.channels[signal_channel_index].znull = 0
+        self.channels[signal_channel_index].null = 0
         self.channels[signal_channel_index]._update()
 
     def flip(self, axis):
@@ -1042,9 +1042,9 @@ def level(self, channel, axis, npts, verbose=True):
         values = values.transpose(transpose_order)
         # return
         channel.values = values
-        channel.znull = 0.
-        channel.zmax = np.nanmax(values)
-        channel.zmin = np.nanmin(values)
+        channel.null = 0.
+        channel.max = np.nanmax(values)
+        channel.min = np.nanmin(values)
         # print
         if verbose:
             axis = self.axes[axis_index]
@@ -1211,7 +1211,7 @@ def map_axis(self, axis, points, input_units='same', verbose=True):
 
     def normalize(self, channel=0, axis=None):
         """
-        Normalize data in given channel so that null=0 and zmax=1.
+        Normalize data in given channel so that null=0 and max=1.
 
         Parameters
         ----------
@@ -1997,7 +1997,7 @@ def from_BrunoldrRaman(filepath, name=None, verbose=True):
 
 def from_COLORS(
         filepaths,
-        znull=None,
+        null=None,
         name=None,
         cols=None,
         invert_d1=True,
@@ -2393,8 +2393,8 @@ def from_KENT(filepaths, null=None, name=None, ignore=['wm'], use_norm=False,
         #data_norm = data.channels[0].values*data.axes[0].points*data.axes[1].points/(OPA1*OPA2)
         data_norm = data.channels[0].values / (OPA1 * OPA2)  # I think this is correct.
         data.channels[0].values = data_norm
-        data.channels[0].zmax = data_norm.max()
-        data.channels[0].zmin = data_norm.min()
+        data.channels[0].max = data_norm.max()
+        data.channels[0].min = data_norm.min()
     # return --------------------------------------------------------------------------------------
     if verbose:
         print('data object succesfully created')


Test patch:
Repository: wright-group/WrightTools

Issue:
Make magic functions and __init__ show up in generated documentation
These functions are quite necessary for the end users to know exist and how to use if there is anything ambiguous (or, say, how to create an object)


Discussion:

Resolving patch:
diff --git a/WrightTools/data.py b/WrightTools/data.py
--- a/WrightTools/data.py
+++ b/WrightTools/data.py
@@ -67,7 +67,7 @@ def __init__(self, points, units, symbol_type=None,
                  name='', label_seed=[''], **kwargs):
         """Create an `Axis` object.
 
-        Paramaters
+        Parameters
         ----------
         points : 1D array-like
             Axis points.
@@ -2916,8 +2916,8 @@ def join(datas, method='first', verbose=True, **kwargs):
     verbose : bool (optional)
         Toggle talkback. Default is True.
 
-    kwargs
-    ------
+    Keyword Arguments
+    -----------------
     axis objects
         The axes of the new data object. If not supplied, the points of the
         new axis will be guessed from the given datas.


Test patch:
Repository: wright-group/WrightTools

Issue:
add imageio as dependency



Discussion:

Resolving patch:
diff --git a/WrightTools/artists.py b/WrightTools/artists.py
--- a/WrightTools/artists.py
+++ b/WrightTools/artists.py
@@ -30,6 +30,8 @@
 from matplotlib.backends.backend_pdf import PdfPages
 import matplotlib.patheffects as PathEffects
 
+import imageio
+
 from . import kit as wt_kit
 
 
@@ -1421,12 +1423,6 @@ def stitch_to_animation(images, outpath=None, duration=0.5, palettesize=256,
     verbose : bool (optional)
         Toggle talkback. Default is True.
     """
-    # import imageio
-    try:
-        import imageio
-    except ImportError:
-        raise ImportError(
-            'WrightTools.artists.stitch_to_animation requires imageio - https://imageio.github.io/')
     # parse filename
     if outpath is None:
         outpath = os.path.splitext(images[0])[0] + '.gif'


Test patch:
Repository: wright-group/WrightTools

Issue:
wt.artists.Axes.contourf() is broken due to TypeError
`wt.artists.Axes.contourf()` attempts to add a `tuple` and a `list` together when calling `matplotlib.axes.Axes.contour()`. See [this line of code](https://github.com/wright-group/WrightTools/blob/development/WrightTools/artists.py#L126).


Discussion:
good catch @darienmorrow 

try something like this
 
``` python
        kwargs['antialiased'] = False
        kwargs['extend'] = 'both'
        contours = matplotlib.axes.Axes.contourf(self, *args, **kwargs)  # why can't I use super?
        # fill lines
        zorder = contours.collections[0].zorder - 0.1
        levels = (contours.levels[1:] + contours.levels[:-1]) / 2
        matplotlib.axes.Axes.contour(self, *args[:3], levels=levels,
                                     cmap=contours.cmap,
                                     zorder=zorder)
        # PathCollection modifications
        for c in contours.collections:
            pass
            # c.set_rasterized(True)
            # c.set_edgecolor('face')
        return contours
```

Resolving patch:
diff --git a/WrightTools/artists.py b/WrightTools/artists.py
--- a/WrightTools/artists.py
+++ b/WrightTools/artists.py
@@ -121,7 +121,8 @@ def contourf(self, *args, **kwargs):
         contours = matplotlib.axes.Axes.contourf(self, *args, **kwargs)  # why can't I use super?
         # fill lines
         zorder = contours.collections[0].zorder - 0.1
-        matplotlib.axes.Axes.contour(self, *(args[:3] + [len(contours.levels)]),
+        levels = (contours.levels[1:] + contours.levels[:-1]) / 2
+        matplotlib.axes.Axes.contour(self, *args[:3], levels=levels,
                                      cmap=contours.cmap,
                                      zorder=zorder)
         # PathCollection modifications


Test patch:
Repository: wright-group/WrightTools

Issue:
distribute client_secrets



Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -3,6 +3,7 @@
 import os
 from setuptools import setup, find_packages
 
+
 def package_files(directory):
     paths = []
     for (path, directories, filenames) in os.walk(directory):
@@ -10,6 +11,7 @@ def package_files(directory):
             paths.append(os.path.join('..', path, filename))
     return paths
 
+
 here = os.path.abspath(os.path.dirname(__file__))
 
 extra_files = package_files(os.path.join(here, 'WrightTools', 'datasets'))
@@ -18,6 +20,7 @@ def package_files(directory):
 extra_files.append(os.path.join(here, 'README.rst'))
 extra_files.append(os.path.join(here, 'requirements.txt'))
 extra_files.append(os.path.join(here, 'VERSION'))
+extra_files.append(os.path.join(here, 'WrightTools', 'client_secrets.json'))
 
 with open(os.path.join(here, 'requirements.txt')) as f:
     required = f.read().splitlines()


Test patch:
Repository: wright-group/WrightTools

Issue:
using 'sorted' causes lists to be returned, breaking downstream operations



Discussion:

Resolving patch:
diff --git a/WrightTools/calibration.py b/WrightTools/calibration.py
--- a/WrightTools/calibration.py
+++ b/WrightTools/calibration.py
@@ -200,7 +200,7 @@ def map_points(self, points, units='same'):
         # convert new points to local units
         if units == 'same':
             units = self.control_units
-        new_points = sorted(wt_units.converter(new_points, units, self.control_units))
+        new_points = np.sort(wt_units.converter(new_points, units, self.control_units))
         new_values = self.get_offset(new_points)
         # finish
         self.points = new_points
diff --git a/WrightTools/tuning/coset.py b/WrightTools/tuning/coset.py
--- a/WrightTools/tuning/coset.py
+++ b/WrightTools/tuning/coset.py
@@ -206,7 +206,7 @@ def map_control_points(self, points, units='same'):
         # convert new points to local units
         if units == 'same':
             units = self.control_units
-        new_points = sorted(wt_units.converter(new_points, units, self.control_units))
+        new_points = np.sort(wt_units.converter(new_points, units, self.control_units))
         new_offsets = self.get_offset(new_points)
         # finish
         self.control_points = new_points
diff --git a/WrightTools/tuning/curve.py b/WrightTools/tuning/curve.py
--- a/WrightTools/tuning/curve.py
+++ b/WrightTools/tuning/curve.py
@@ -457,7 +457,7 @@ def map_colors(self, colors, units='same'):
         # convert new colors to local units
         if units == 'same':
             units = self.units
-        new_colors = sorted(wt_units.converter(new_colors, units, self.units))
+        new_colors = np.sort(wt_units.converter(new_colors, units, self.units))
         # ensure that motor interpolators agree with current motor positions
         self.interpolate(interpolate_subcurve=True)
         # map own motors


Test patch:
Repository: wright-group/WrightTools

Issue:
make setup.py an executable script
Change file permissions and reformat the shebang line


Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
old mode 100644
new mode 100755
--- a/setup.py
+++ b/setup.py
@@ -1,4 +1,4 @@
-# !/usr/bin/env python
+#! /usr/bin/env python
 
 import os
 from setuptools import setup, find_packages


Test patch:
Repository: wright-group/WrightTools

Issue:
`wt.artists.mpl_2D.plot()` has possibly undesirable behavior RE: filename default
This [line](https://github.com/wright-group/WrightTools/blob/development/WrightTools/artists.py#L2215) raises `AttributeError: 'NoneType' object has no attribute 'endswith'` if nothing is specified by the user for the `fname` kwarg of `wt.artists.mpl_2D.plot()`.

Is the desired workflow that the user _always_ needs to give a filename to `plot` if saving? 


Discussion:
no, of course not---I'm so sorry that you have encountered this behavior @darienmorrow 

I believe this was broken by @neffmallon when pdf support was added

I will attempt to fix
Will note that a hack for making it run is just to hand it `fname = ''` 😏 

Resolving patch:
diff --git a/WrightTools/artists.py b/WrightTools/artists.py
--- a/WrightTools/artists.py
+++ b/WrightTools/artists.py
@@ -1901,7 +1901,7 @@ def plot(self, channel=0,
         output_folder : str (optional)
             Output folder.
         fname : str (optional)
-            File name.
+            File name. If None, data name is used. Default is None.
         verbose : bool (optional)
             Toggle talkback. Default is True.
         """
@@ -1912,6 +1912,11 @@ def plot(self, channel=0,
             channel_index = self.chopped[0].channel_names.index(channel)
         else:
             print('channel type not recognized in mpl_2D!')
+        # get fname
+        if fname:
+            pass
+        else:
+            fname = self.data.name
         # prepare figure
         fig = None
         if len(self.chopped) > 10:
@@ -1925,10 +1930,6 @@ def plot(self, channel=0,
             else:
                 if len(self.chopped) == 1:
                     output_folder = os.getcwd()
-                    if fname:
-                        pass
-                    else:
-                        fname = self.data.name
                 else:
                     folder_name = 'mpl_2D ' + wt_kit.get_timestamp(style='short')
                     os.mkdir(folder_name)


Test patch:
Repository: wright-group/WrightTools

Issue:
wt.google_drive.Drive.download() calls `self._list_folder()` when it should call `self.list_folder()`
See offending [line](https://github.com/wright-group/WrightTools/blob/039507d95561fd237dc7ba66b4d4f37ce6148397/WrightTools/google_drive.py#L248).

[Line](https://github.com/wright-group/WrightTools/blob/039507d95561fd237dc7ba66b4d4f37ce6148397/WrightTools/google_drive.py#L281) where correct method is defined. 



Discussion:

Resolving patch:
diff --git a/WrightTools/google_drive.py b/WrightTools/google_drive.py
--- a/WrightTools/google_drive.py
+++ b/WrightTools/google_drive.py
@@ -245,7 +245,7 @@ def download(self, fileid, directory='cwd', overwrite=False, verbose=True):
             if not os.path.isdir(f_path):
                 os.mkdir(f_path)
             # fill contents
-            for child_id in self._list_folder(fileid):
+            for child_id in self.list_folder(fileid):
                 self.download(child_id, directory=f_path)
         else:  # single file
             # check if file exists


Test patch:
Repository: wright-group/WrightTools

Issue:
remove revert
:no_good_man: 


Discussion:

Resolving patch:
diff --git a/WrightTools/data/_data.py b/WrightTools/data/_data.py
--- a/WrightTools/data/_data.py
+++ b/WrightTools/data/_data.py
@@ -10,7 +10,6 @@
 .. _kaiser window: https://en.wikipedia.org/wiki/Kaiser_window
 .. _scipy ndimage:
     http://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.interpolation.zoom.html
-.. _spcm: http://www.becker-hickl.com/software/spcm.htm
 """
 
 
@@ -525,8 +524,6 @@ def __init__(self, axes, channels, constants=[],
         self.attrs = {}
         # update
         self._update()
-        # reserve a copy of own self at this stage
-        self._original = self.copy()
 
     def __repr__(self):
         """Return an unambiguous representation.
@@ -1520,18 +1517,6 @@ def remove_channel(self, channel):
         # finish
         self._update()
 
-    def revert(self):
-        """Revert this data object back to its original state."""
-        for attribute_name in dir(self):
-            if attribute_name not in ['_original'] + wt_kit.get_methods(self):
-                # if attribute does not exist in original, delete it
-                try:
-                    original_attribute = getattr(self._original, attribute_name)
-                    setattr(self, attribute_name, original_attribute)
-                except AttributeError:
-                    delattr(self, attribute_name)
-        self._update()
-
     def save(self, filepath=None, verbose=True):
         """Save using the `pickle`_ module.
 
diff --git a/WrightTools/data/_spcm.py b/WrightTools/data/_spcm.py
--- a/WrightTools/data/_spcm.py
+++ b/WrightTools/data/_spcm.py
@@ -1,4 +1,7 @@
-"""SPCM."""
+"""SPCM.
+
+.. _spcm: http://www.becker-hickl.com/software/spcm.htm
+"""
 
 
 # --- import --------------------------------------------------------------------------------------


Test patch:
Repository: wright-group/WrightTools

Issue:
remove true_max, true_min



Discussion:

Resolving patch:
diff --git a/WrightTools/data/_data.py b/WrightTools/data/_data.py
--- a/WrightTools/data/_data.py
+++ b/WrightTools/data/_data.py
@@ -47,16 +47,6 @@
     string_type = str  # newer versions of python don't have unicode type
 
 
-def true_max(*args, **kwargs):
-    """Call standard library max function."""
-    return max(*args, **kwargs)
-
-
-def true_min(*args, **kwargs):
-    """Call standard library min function."""
-    return min(*args, **kwargs)
-
-
 __all__ = ['Axis', 'Channel', 'Data']
 
 


Test patch:
Repository: wright-group/WrightTools

Issue:
data.collapse nan behavior
sum and average could behave better w.r.t. nans


Discussion:

Resolving patch:
diff --git a/WrightTools/data/_data.py b/WrightTools/data/_data.py
--- a/WrightTools/data/_data.py
+++ b/WrightTools/data/_data.py
@@ -719,7 +719,7 @@ def collapse(self, axis, method='integrate'):
         method : {'integrate', 'average', 'sum', 'max', 'min'} (optional)
             The method of collapsing the given axis. Method may also be list
             of methods corresponding to the channels of the object. Default
-            is integrate.
+            is integrate. All methods but integrate disregard NANs.
 
         See Also
         --------
@@ -749,13 +749,13 @@ def collapse(self, axis, method='integrate'):
                 channel.values = np.trapz(
                     y=channel.values, x=self.axes[axis_index].points, axis=axis_index)
             elif method == 'sum':
-                channel.values = channel.values.sum(axis=axis_index)
+                channel.values = np.nansum(channel.values, axis=axis_index)
             elif method in ['max', 'maximum']:
                 channel.values = np.nanmax(channel.values, axis=axis_index)
             elif method in ['min', 'minimum']:
                 channel.values = np.nanmin(channel.values, axis=axis_index)
-            elif method in ['ave', 'average']:
-                channel.values = np.average(channel.values, axis=axis_index)
+            elif method in ['ave', 'average', 'mean']:
+                channel.values = np.nanmean(channel.values, axis=axis_index)
             else:
                 print('method not recognized in data.collapse')
         # cleanup ---------------------------------------------------------------------------------


Test patch:
Repository: wright-group/WrightTools

Issue:
symmetric sqrt
tired of writing and rewriting symmetric sqrt operations in everything that I do


Discussion:

Resolving patch:
diff --git a/WrightTools/data/_data.py b/WrightTools/data/_data.py
--- a/WrightTools/data/_data.py
+++ b/WrightTools/data/_data.py
@@ -1548,12 +1548,7 @@ def scale(self, channel=0, kind='amplitude', verbose=True):
         channel = self.channels[channel_index]
         # do scaling
         if kind in ['amp', 'amplitude']:
-            channel_data = channel.values
-            channel_data_abs = np.sqrt(np.abs(channel_data))
-            factor = np.ones(channel_data.shape)
-            factor[channel_data < 0] = -1
-            channel_data_out = channel_data_abs * factor
-            channel.values = channel_data_out
+            channel.values = wt_kit.symmetric_sqrt(channel.values, out=channel.values)
         if kind in ['log']:
             channel.values = np.log10(channel.values)
         if kind in ['invert']:
diff --git a/WrightTools/kit.py b/WrightTools/kit.py
--- a/WrightTools/kit.py
+++ b/WrightTools/kit.py
@@ -1056,6 +1056,29 @@ def __init__(self, xi, yi, k=3, s=1000, ignore_nans=True):
         self.true_spline = UnivariateSpline(xi_internal, yi_internal, k=k, s=s)
 
 
+def symmetric_sqrt(x, out=None):
+    """Compute the 'symmetric' square root: sign(x) * sqrt(abs(x)).
+
+    Parameters
+    ----------
+    x : array_like or number
+        Input array.
+    out : ndarray, None, or tuple of ndarray and None (optional)
+        A location into which the result is stored. If provided, it must
+        have a shape that the inputs broadcast to. If not provided or None,
+        a freshly-allocated array is returned. A tuple (possible only as a
+        keyword argument) must have length equal to the number of outputs.
+
+    Returns
+    -------
+    np.ndarray
+        Symmetric square root of arr.
+    """
+    factor = np.sign(x)
+    out = np.sqrt(np.abs(x), out=out)
+    return out * factor
+
+
 def unique(arr, tolerance=1e-6):
     """Return unique elements in 1D array, within tolerance.
 


Test patch:
diff --git a/tests/kit/.gitignore b/tests/kit/.gitignore
new file mode 100644
diff --git a/tests/kit/__init__.py b/tests/kit/__init__.py
new file mode 100644
diff --git a/tests/kit/symmetric_sqrt.py b/tests/kit/symmetric_sqrt.py
new file mode 100644
--- /dev/null
+++ b/tests/kit/symmetric_sqrt.py
@@ -0,0 +1,19 @@
+"""test symmetric_sqrt"""
+
+
+# --- import --------------------------------------------------------------------------------------
+
+
+import numpy as np
+
+import WrightTools as wt
+
+
+# --- test ----------------------------------------------------------------------------------------
+
+
+def test_numbers():
+    numbers = np.random.normal(size=100)
+    for number in numbers:
+        answer = wt.kit.symmetric_sqrt(number)
+        assert answer == np.sign(number) * np.sqrt(np.abs(number))
diff --git a/tests/tuning/__init__.py b/tests/tuning/__init__.py
new file mode 100644
diff --git a/tests/tuning/spectral_delay_correction/__init__.py b/tests/tuning/spectral_delay_correction/__init__.py
new file mode 100644
Repository: wright-group/WrightTools

Issue:
flatten list



Discussion:

Resolving patch:
diff --git a/WrightTools/kit.py b/WrightTools/kit.py
--- a/WrightTools/kit.py
+++ b/WrightTools/kit.py
@@ -5,7 +5,6 @@
 .. _RFC5322: https://tools.ietf.org/html/rfc5322#section-3.3
 .. _HDF5: https://www.hdfgroup.org/HDF5/doc/H5.intro.html
 .. _intersperse: http://stackoverflow.com/a/5921708
-.. _flatten: http://stackoverflow.com/questions/2158395
 .. _suppress:
     http://stackoverflow.com/questions/11130156/suppress-stdout-stderr-print-from-python-functions
 """
@@ -1153,36 +1152,43 @@ def array2string(array, sep='\t'):
     return string
 
 
-def flatten_list(l):
-    """Flatten an irregular list.
+def flatten_list(items, seqtypes=(list, tuple), in_place=True):
+    """Flatten an irregular sequence.
 
     Works generally but may be slower than it could
     be if you can make assumptions about your list.
 
-
     `Source`__
 
-    __ flatten_
+    __ https://stackoverflow.com/a/10824086
 
+    Parameters
+    ----------
+    items : iterable
+        The irregular sequence to flatten.
+    seqtypes : iterable of types (optional)
+        Types to flatten. Default is (list, tuple).
+    in_place : boolean (optional)
+        Toggle in_place flattening. Default is True.
 
-        >>> l = [[[1, 2, 3], [4, 5]], 6]
-        >>> wt.kit.flatten_list(l)
-        [1, 2, 3, 4, 5, 6]
+    Returns
+    -------
+    list
+        Flattened list.
+
+    Examples
+    --------
 
+    >>> l = [[[1, 2, 3], [4, 5]], 6]
+    >>> wt.kit.flatten_list(l)
+    [1, 2, 3, 4, 5, 6]
     """
-    listIsNested = True
-    while listIsNested:  # outer loop
-        keepChecking = False
-        Temp = []
-        for element in l:  # inner loop
-            if isinstance(element, list):
-                Temp.extend(element)
-                keepChecking = True
-            else:
-                Temp.append(element)
-        listIsNested = keepChecking  # determine if outer loop exits
-        lis = Temp[:]
-    return lis
+    if not in_place:
+        items = items[:]
+    for i, _ in enumerate(items):
+        while i < len(items) and isinstance(items[i], seqtypes):
+            items[i:i + 1] = items[i]
+    return items
 
 
 def get_methods(the_class, class_only=False, instance_only=False,


Test patch:
diff --git a/tests/kit/flatten_list.py b/tests/kit/flatten_list.py
new file mode 100644
--- /dev/null
+++ b/tests/kit/flatten_list.py
@@ -0,0 +1,16 @@
+"""test flatten_list"""
+
+
+# --- import --------------------------------------------------------------------------------------
+
+
+import WrightTools as wt
+
+
+# --- test ----------------------------------------------------------------------------------------
+
+
+def test_list():
+    input = [[[1, 2, 3], [4, 5]], 6]
+    output = wt.kit.flatten_list(input)
+    assert output == [1, 2, 3, 4, 5, 6]