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

Issue:
Undocumented argument `coloring` in plot_data
https://github.com/wright-group/WrightTools/blob/f740e82f9691a386c6997cb15a6399839ea84002/WrightTools/artists.py#L157


Discussion:
Further, the documented `cmap` argument does nothing, the functionality is in `coloring` but just overwrites the `cmap` variable...

`coloring` is confusing and should perhaps be changed, my leaning would be to expose `plot` kwargs, allowing cmap to work as intended, but giving users more control over the formatting of the actual plot call
Related: I feel inclined to allow cmap to be an actual color map object (in addition to the key to our dictionary of defaults), which is not supported in the current code

Resolving patch:
diff --git a/WrightTools/artists.py b/WrightTools/artists.py
--- a/WrightTools/artists.py
+++ b/WrightTools/artists.py
@@ -451,7 +451,7 @@ def plot(self, *args, **kwargs):
 
     def plot_data(self, data, channel=0, interpolate=False, coloring=None,
                   xlabel=True, ylabel=True, min=None, max=None):
-        """Plot directly from a data object.
+        """DEPRECATED.
 
         Parameters
         ----------
@@ -461,9 +461,10 @@ def plot_data(self, data, channel=0, interpolate=False, coloring=None,
             The channel to plot. Default is 0.
         interpolate : boolean (optional)
             Toggle interpolation. Default is False.
-        cmap : str (optional)
-            A key to the colormaps dictionary found in artists module. Default
-            is None (inherits from channel).
+        coloring : str (optional)
+            A key to the colormaps dictionary found in artists module, for
+            two-dimensional data. A matplotlib color string for
+            one-dimensional data. Default is None.
         xlabel : boolean (optional)
             Toggle xlabel. Default is True.
         ylabel : boolean (optional)
@@ -473,7 +474,6 @@ def plot_data(self, data, channel=0, interpolate=False, coloring=None,
         max : number (optional)
             max. Default is None (inherited from channel).
 
-
         .. plot::
 
            >>> import matplotlib


Test patch:
Repository: wright-group/WrightTools

Issue:
Raise issue in calibration for dimensionality too high
https://github.com/wright-group/WrightTools/blob/44da87cf4dfa18f87bdd699b832066ace50f6ec1/WrightTools/calibration.py#L263

This one I could see requiring changes to gracefully catch the exception thrown here, but Feel an exception is more clear than a print/return



Discussion:

Resolving patch:
diff --git a/WrightTools/calibration.py b/WrightTools/calibration.py
--- a/WrightTools/calibration.py
+++ b/WrightTools/calibration.py
@@ -260,8 +260,7 @@ def plot(self, autosave=False, save_directory=None, file_name=None):
             wt_artists.plot_colorbar(cax=cax, ticks=ticks)
             plt.suptitle(self.name, fontsize=20)
         else:
-            print('cannot plot---dimensionality too high')
-            return
+            raise wt_exceptions.DimensionalityError("{1, 2}", self.dimensionality)
         # save
         if autosave:
             if save_directory is None:


Test patch:
Repository: wright-group/WrightTools

Issue:
`ax.contourf()` doesn't handle colormap kwarg as expected
`ax.contourf(x,y,z.T,cmap=cmap)` when `ax` is an `wt.artist` axes ought to be able to accept a `cmap` of either a string or a matplotlib colormap. It does neither and just defaults to the `default` colormap.


Discussion:

Resolving patch:
diff --git a/WrightTools/artists.py b/WrightTools/artists.py
--- a/WrightTools/artists.py
+++ b/WrightTools/artists.py
@@ -58,9 +58,9 @@ class Axes(matplotlib.axes.Axes):
 
     def _parse_cmap(self, data=None, channel_index=None, **kwargs):
         if 'cmap' in kwargs.keys():
-            if isinstance(cmap, string_type):
+            if isinstance(kwargs['cmap'], string_type):
                 kwargs['cmap'] = colormaps[kwargs['cmap']]
-                return kwargs
+            return kwargs
         if data:
             if data.channels[channel_index].signed:
                 kwargs['cmap'] = colormaps['signed']


Test patch:
Repository: wright-group/WrightTools

Issue:
raise exception when natural naming broken
We may want to have some kind of check to make sure data objects are well formed when creating data objects so that the code stops before we try to do other things with it. For an example of when this might happen, see issue #279. I'm not sure how to tag this appropriately.


Discussion:
what exactly would you have us do?

as far as I know, having overlapping channel names doesn't actually break the data object---it just means you can't use natural naming anymore

if you want, we can raise an exception if names are not unique
I think that is probably a good idea/design choice, but I tagged it discussion because it is just an idea and wanted to see what other people thought about it. ~Nathan
Recent changes have been at least moving towards requiring unique names. `rename_attrs` expects and will only make changes if uniqueness is preserved
we now plan to raise an exception in `Data._update` if natural naming is broken

Resolving patch:
diff --git a/WrightTools/data/_data.py b/WrightTools/data/_data.py
--- a/WrightTools/data/_data.py
+++ b/WrightTools/data/_data.py
@@ -588,8 +588,7 @@ def _update(self):
         if len(all_names) == len(set(all_names)):
             pass
         else:
-            print('axis, constant, and channel names must all be unique')
-            return
+            raise RuntimeError('names must be unique')
         for obj in self.axes + self.channels + self.constants:
             identifier = obj.name.split('/')[-1]
             setattr(self, identifier, obj)
@@ -928,13 +927,14 @@ def create_channel(self, name, values=None, units=None, **kwargs):
         """
         if values is None:
             shape = self.shape
+            dtype = np.float64
         else:
             shape = values.shape
+            dtype = values.dtype
             if not shape == self.shape:
                 raise Exception  # TODO: better exception
         # create dataset
-        id = self.require_dataset(name=name, data=values, shape=values.shape,
-                                  dtype=values.dtype).id
+        id = self.require_dataset(name=name, data=values, shape=shape, dtype=dtype).id
         channel = Channel(self, id, units=units, **kwargs)
         self.channels.append(channel)
         self.attrs['channel_names'] = np.append(self.attrs['channel_names'], name.encode())


Test patch:
diff --git a/tests/data/unique_names.py b/tests/data/unique_names.py
new file mode 100644
--- /dev/null
+++ b/tests/data/unique_names.py
@@ -0,0 +1,24 @@
+"""Test that names are kept unique in data."""
+
+
+# --- import -------------------------------------------------------------------------------------
+
+
+import numpy as np
+
+import WrightTools as wt
+
+
+# --- test ---------------------------------------------------------------------------------------
+
+
+def test_exception():
+    d = wt.Data()
+    points = np.linspace(0, 1, 51)
+    d.create_axis(name='w1', points=points, units='eV')
+    try:
+        d.create_channel(name='w1') 
+    except RuntimeError:
+        assert True
+    else:
+        assert False
Repository: wright-group/WrightTools

Issue:
coverage
consider using [coverage](https://coverage.readthedocs.io/en/coverage-4.4.1/)


Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -33,7 +33,7 @@ def package_files(directory):
     packages=find_packages(),
     package_data={'': extra_files},
     setup_requires=['pytest-runner'],
-    tests_require=['pytest'],
+    tests_require=['pytest', 'pytest-cov'],
     install_requires=required,
     extras_require={'docs': ['sphinx-gallery>=0.1.9']},
     version=version,


Test patch:
Repository: wright-group/WrightTools

Issue:
Windows Tempfile Error
On Windows, tempfiles attempted to be opened using h5py cause errors.

I do not have the error message in front of me at present, but I believe it was a 'file already exists' flavor of problem. 

We may need to remove the created tmpfile and just use the name....


Discussion:

Resolving patch:
diff --git a/WrightTools/_base.py b/WrightTools/_base.py
--- a/WrightTools/_base.py
+++ b/WrightTools/_base.py
@@ -5,6 +5,7 @@
 
 
 import shutil
+import os
 import weakref
 import tempfile
 import posixpath
@@ -74,8 +75,8 @@ def __new__(cls, *args, **kwargs):
         if edit_local and filepath is None:
             raise Exception  # TODO: better exception
         if not edit_local:
-            tmpfile = tempfile.NamedTemporaryFile(prefix='', suffix='.wt5')
-            p = tmpfile.name
+            tmpfile = tempfile.mkstemp(prefix='', suffix='.wt5')
+            p = tmpfile[1]
             if filepath:
                 shutil.copyfile(src=filepath, dst=p)
         elif edit_local and filepath:
@@ -137,7 +138,8 @@ def close(self):
             self.file.flush()
             self.file.close()
             if hasattr(self, '_tmpfile'):
-                self._tmpfile.close()
+                os.close(self._tmpfile[0])
+                os.remove(self._tmpfile[1])
 
     def flush(self):
         self.file.flush()


Test patch:
Repository: wright-group/WrightTools

Issue:
collection.keys returns data objects
should return names, but get objects


Discussion:
This is happening because we overwrote the `__next__` method.

In the underlying h5py, __next__ is inherited from far upstream, and provides the keys, which can then be used to get the items

one way to fix it would be to make `__next__` return the key rather than the objects themselves

Another way to fix would be to override Keys, note however that doing so would likely mean making it a list, rather than a KeysView, which updates if the object updates


Resolving patch:
diff --git a/WrightTools/collection/_collection.py b/WrightTools/collection/_collection.py
--- a/WrightTools/collection/_collection.py
+++ b/WrightTools/collection/_collection.py
@@ -37,7 +37,7 @@ def __len__(self):
 
     def __next__(self):
         if self.__n < len(self):
-            out = self[self.__n]
+            out = self.item_names[self.__n]
             self.__n += 1
         else:
             raise StopIteration


Test patch:
Repository: wright-group/WrightTools

Issue:
raise exception when natural naming broken
We may want to have some kind of check to make sure data objects are well formed when creating data objects so that the code stops before we try to do other things with it. For an example of when this might happen, see issue #279. I'm not sure how to tag this appropriately.


Discussion:
what exactly would you have us do?

as far as I know, having overlapping channel names doesn't actually break the data object---it just means you can't use natural naming anymore

if you want, we can raise an exception if names are not unique
I think that is probably a good idea/design choice, but I tagged it discussion because it is just an idea and wanted to see what other people thought about it. ~Nathan
Recent changes have been at least moving towards requiring unique names. `rename_attrs` expects and will only make changes if uniqueness is preserved
we now plan to raise an exception in `Data._update` if natural naming is broken
Should be wt.exceptions.NameNotUniqueError, not a generic RuntimeError

Resolving patch:
diff --git a/WrightTools/data/_data.py b/WrightTools/data/_data.py
--- a/WrightTools/data/_data.py
+++ b/WrightTools/data/_data.py
@@ -588,7 +588,7 @@ def _update(self):
         if len(all_names) == len(set(all_names)):
             pass
         else:
-            raise RuntimeError('names must be unique')
+            raise wt_exceptions.NameNotUniqueError()
         for obj in self.axes + self.channels + self.constants:
             identifier = obj.name.split('/')[-1]
             setattr(self, identifier, obj)
diff --git a/WrightTools/exceptions.py b/WrightTools/exceptions.py
--- a/WrightTools/exceptions.py
+++ b/WrightTools/exceptions.py
@@ -47,7 +47,7 @@ def __init__(self, path):
 class NameNotUniqueError(Exception):
     """NameNotUniqueError."""
 
-    def __init__(self, name):
+    def __init__(self, name=None):
         """Format a Name Not Unique Error.
 
         Parameters
@@ -55,7 +55,10 @@ def __init__(self, name):
         name : string
             Name of an attribute which causes a duplication.
         """
-        message = 'Name {} results in a duplicate'.format(name)
+        if name is not None:
+            message = 'Name {} results in a duplicate'.format(name)
+        else:
+            message = "Names must be unique"
         Exception.__init__(self, message)
 
 


Test patch:
diff --git a/tests/data/rename_attrs.py b/tests/data/rename_attrs.py
--- a/tests/data/rename_attrs.py
+++ b/tests/data/rename_attrs.py
@@ -23,7 +23,6 @@ def test_rename():
     data.close()
 
 
-@pytest.mark.skip()
 def test_error():
     p = datasets.PyCMDS.wm_w2_w1_000
     data = wt.data.from_PyCMDS(p)
diff --git a/tests/data/unique_names.py b/tests/data/unique_names.py
--- a/tests/data/unique_names.py
+++ b/tests/data/unique_names.py
@@ -18,7 +18,7 @@ def test_exception():
     d.create_axis(name='w1', points=points, units='eV')
     try:
         d.create_channel(name='w1') 
-    except RuntimeError:
+    except wt.exceptions.NameNotUniqueError:
         assert True
     else:
         assert False
Repository: wright-group/WrightTools

Issue:
warnings not defined in wt.artists (version 2.13.9)
`File "/home/darien/source/WrightTools/WrightTools/artists.py", line 485, in plot_data`
`warnings.warn(wt_exceptions.VisibleDeprecationWarning(message))`
`NameError: name 'warnings' is not defined`



Discussion:

Resolving patch:
diff --git a/WrightTools/artists.py b/WrightTools/artists.py
--- a/WrightTools/artists.py
+++ b/WrightTools/artists.py
@@ -32,6 +32,8 @@
 
 import imageio
 
+import warnings
+
 from . import exceptions as wt_exceptions
 from . import data as wt_data
 from . import kit as wt_kit


Test patch:
Repository: wright-group/WrightTools

Issue:
COLORS and KENT `source` not included in attrs
```
WrightTools/WrightTools/_group.py:62: UserWarning: 'source' not included in attrs because its Type cannot be represented
    key)
```

This warning is produced in several tests, I believe that there is a missing conversion from string to bytes


Discussion:

Resolving patch:
diff --git a/WrightTools/_group.py b/WrightTools/_group.py
--- a/WrightTools/_group.py
+++ b/WrightTools/_group.py
@@ -55,11 +55,15 @@ def __init__(self, filepath=None, parent=None, name=None, **kwargs):
         self.attrs['class'] = self.class_name
         for key, value in kwargs.items():
             try:
+                if isinstance(value, str):
+                    value = value.encode()
+                elif isinstance(value, list) and len(value) > 0 and isinstance(value[0], str):
+                    value = np.array(value, dtype='S')
                 self.attrs[key] = value
             except TypeError:
                 # some values have no native HDF5 equivalent
-                warnings.warn("'%s' not included in attrs because its Type cannot be represented" %
-                              key)
+                warnings.warn("'%s' not included in attrs because its Type (%s) cannot be represented" %
+                              (key, type(value)))
         # load from file
         self._items = []
         for name in self.item_names:


Test patch:
Repository: wright-group/WrightTools

Issue:
print(kwargs) in wt.artists.plot is annoying
Is this [line](https://github.com/wright-group/WrightTools/blob/master/WrightTools/artists.py#L450) necessary? It leads to things like `{'linewidth': 3}` being repeatedly printed when called recursively. 

I will note that the overloaded methods `pcolor`, `contour` and `contourf` don't seem to have this line in their definition. So for consistency they all should all have it or none should have it?


Discussion:
Almost certainly, this was put in for debugging purposes, and can be removed
I went to fix this, but it seems to have been already fixed in development. Thanks @untzag! 
Reopening as a backports issue, it has been fixed in development (3.0), but not in the 2.X series

Resolving patch:
diff --git a/WrightTools/artists.py b/WrightTools/artists.py
--- a/WrightTools/artists.py
+++ b/WrightTools/artists.py
@@ -454,7 +454,6 @@ def plot(self, *args, **kwargs):
                            ylabel=kwargs.pop('ylabel', None),
                            data=data, channel_index=channel_index)
         # call parent
-        print(kwargs)
         return matplotlib.axes.Axes.plot(self, *args, **kwargs)  # why can't I use super?
 
     def plot_data(self, data, channel=0, interpolate=False, coloring=None,


Test patch:
Repository: wright-group/WrightTools

Issue:
Recover data.smooth



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
@@ -1157,6 +1157,8 @@ def share_nans(self):
     def smooth(self, factors, channel=None, verbose=True):
         """Smooth a channel using an n-dimenional `kaiser window`__.
 
+        Note, all arrays are loaded into memory.
+
         __ https://en.wikipedia.org/wiki/Kaiser_window
 
         Parameters
@@ -1170,7 +1172,6 @@ def smooth(self, factors, channel=None, verbose=True):
         verbose : bool (optional)
             Toggle talkback. Default is True.
         """
-        raise NotImplementedError
         # get factors -----------------------------------------------------------------------------
 
         if isinstance(factors, list):


Test patch:
diff --git a/tests/data/smooth.py b/tests/data/smooth.py
new file mode 100644
--- /dev/null
+++ b/tests/data/smooth.py
@@ -0,0 +1,70 @@
+"""Test data.smooth."""
+
+
+# --- import --------------------------------------------------------------------------------------
+
+
+import numpy as np
+
+import WrightTools as wt
+
+import matplotlib.pyplot as plt
+
+
+# --- test ----------------------------------------------------------------------------------------
+
+
+def test_1():
+    # create collection
+    root = wt.Collection(name='root_coll')
+    kwargs = {'name': 'test1'}
+    data = root.create_data(**kwargs)
+    # create test arrays
+    x = np.linspace(0, 1, 1000)
+    y = 1*x
+    # create channels and variables
+    data.create_variable(name='x', values=x, units=None)
+    data.create_channel(name='y', values=y)
+    data.create_channel(name='z', values=y)
+    data.transform(['x'])
+    # smooth
+    data.smooth(5, channel='y')
+    check_arr = data.y[:] - data.z[:]
+    assert np.isclose(check_arr.all(), 0, rtol=1e-4, atol=1e-4)
+
+
+def test_2():
+    # create collection
+    root = wt.Collection(name='root_coll')
+    kwargs = {'name': 'test2'}
+    data = root.create_data(**kwargs)
+    # create test arrays
+    x = np.linspace(0, 1, 100)
+    z = np.random.rand(100, 100)
+    # create channels and variables
+    data.create_variable(name='x1', values=x, units=None)
+    data.create_variable(name='x2', values=x, units=None)
+    data.create_channel(name='z', values=z)
+    data.transform(['x1', 'x2'])
+    # smooth
+    data.smooth(90, channel='z')
+    assert np.allclose(data.z[:], .5, rtol=.1, atol=.4)
+
+
+def test_3():
+    # create collection
+    root = wt.Collection(name='root_coll')
+    kwargs = {'name': 'test3'}
+    data = root.create_data(**kwargs)
+    # create test arrays
+    x = np.linspace(0, 4*np.pi, 1000)
+    z_big = np.sin(x)
+    z_small = np.sin(x*50)
+    z_comb = z_big + .1*z_small
+    # create channels and variables
+    data.create_variable(name='x', values=x, units=None)
+    data.create_channel(name='z_comb', values=z_comb)
+    data.transform(['x'])
+    # smooth
+    data.smooth(10, channel='z_comb')
+    assert np.allclose(data.z_comb[:], z_big, rtol=.1, atol=.05)
Repository: wright-group/WrightTools

Issue:
data.convert should convert all compatable variables (under kwarg)
`data.convert` offers `convert_variables` kwarg that toggles actual rewriting of arrays on disk

currently only active variables are converted

since `data.convert` is already a convenience method that stands for "convert all compatible", the method should be changed to convert all compatible variables---even ones that are not active


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
@@ -459,6 +459,13 @@ def convert(self, destination_units, *, convert_variables=False, verbose=True):
                 axis.convert(destination_units, convert_variables=convert_variables)
                 if verbose:
                     print('axis', axis.expression, 'converted')
+        if convert_variables:
+            for var in self.variables:
+                if wt_units.kind(var.units) == units_kind:
+                    var.convert(destination_units)
+
+                    if verbose:
+                        print('variable', var.natural_name, 'converted')
 
     def create_channel(self, name, values=None, units=None, **kwargs):
         """Append a new channel.


Test patch:
diff --git a/tests/data/convert_data.py b/tests/data/convert_data.py
old mode 100644
new mode 100755
--- a/tests/data/convert_data.py
+++ b/tests/data/convert_data.py
@@ -1,3 +1,4 @@
+#! /usr/bin/env python3
 """Test data unit conversion."""
 
 
@@ -15,13 +16,15 @@
 
 def test_convert_variables():
     p = datasets.KENT.LDS821_TRSF
-    ignore = ['d1', 'd2', 'wm']
+    ignore = ['d1', 'd2']
     data = wt.data.from_KENT(p, ignore=ignore)
     data.convert('meV', convert_variables=True)
     assert data.w1.units == 'meV'
     assert data.w2.units == 'meV'
     assert data['w2'].units == 'meV'
     assert data['w2'].units == 'meV'
+    # tests that 'inactive' variable is converted
+    assert data['wm'].units == 'meV'
     data.close()