internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: pandas-dev/pandas

Issue:
BUG: readback of duplicate columns in a HDFStore table is buggy
http://stackoverflow.com/questions/18646668/pandas-hdfstore-duplicate-items-error/18668217#18668217



Discussion:

Resolving patch:
diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py
--- a/pandas/io/pytables.py
+++ b/pandas/io/pytables.py
@@ -3219,7 +3219,7 @@ def read(self, where=None, columns=None, **kwargs):
         if len(objs) == 1:
             wp = objs[0]
         else:
-            wp = concat(objs, axis=0, verify_integrity=True)
+            wp = concat(objs, axis=0, verify_integrity=False)
 
         # apply the selection filters & axis orderings
         wp = self.process_axes(wp, columns=columns)
@@ -3510,7 +3510,7 @@ def read(self, where=None, columns=None, **kwargs):
         if len(frames) == 1:
             df = frames[0]
         else:
-            df = concat(frames, axis=1, verify_integrity=True)
+            df = concat(frames, axis=1, verify_integrity=False)
 
         # apply the selection filters & axis orderings
         df = self.process_axes(df, columns=columns)


Test patch:
diff --git a/pandas/io/tests/test_pytables.py b/pandas/io/tests/test_pytables.py
--- a/pandas/io/tests/test_pytables.py
+++ b/pandas/io/tests/test_pytables.py
@@ -2296,6 +2296,29 @@ def test_wide_table(self):
         wp = tm.makePanel()
         self._check_roundtrip_table(wp, assert_panel_equal)
 
+    def test_select_with_dups(self):
+
+
+        # single dtypes
+        df = DataFrame(np.random.randn(10,4),columns=['A','A','B','B'])
+        df.index = date_range('20130101 9:30',periods=10,freq='T')
+
+        with ensure_clean(self.path) as store:
+            store.append('df',df)
+            result = store.select('df')
+            assert_frame_equal(result,df)
+
+        # dups accross dtypes
+        df = concat([DataFrame(np.random.randn(10,4),columns=['A','A','B','B']),
+                     DataFrame(np.random.randint(0,10,size=20).reshape(10,2),columns=['A','C'])],
+                    axis=1)
+        df.index = date_range('20130101 9:30',periods=10,freq='T')
+
+        with ensure_clean(self.path) as store:
+            store.append('df',df)
+            result = store.select('df')
+            assert_frame_equal(result,df)
+
     def test_wide_table_dups(self):
         wp = tm.makePanel()
         with ensure_clean(self.path) as store:
Repository: pandas-dev/pandas

Issue:
ENH: Better Exception when trying to set on Series with tuple-index.
Fix this Exception to be better (probably the same `tuple-index` error or something...)

``` python
>>> import pandas.util.testing as tm
>>> ts = tm.makeTimeSeries()
>>> ts[:, 2] = None
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "pandas/core/series.py", line 1061, in __setitem__
    self._set_with(key, value)
  File "pandas/core/series.py", line 1103, in _set_with
    self._set_labels(key, value)
  File "pandas/core/series.py", line 1110, in _set_labels
    indexer = self.index.get_indexer(key)
  File "pandas/core/index.py", line 920, in get_indexer
    return this.get_indexer(target, method=method, limit=limit)
  File "pandas/core/index.py", line 935, in get_indexer
    indexer = self._engine.get_indexer(target.values)
  File "index.pyx", line 267, in pandas.index.IndexEngine.get_indexer (pandas/index.c:5079)
  File "hashtable.pyx", line 722, in pandas.hashtable.PyObjectHashTable.lookup (pandas/hashtable.c:11394)
TypeError: unhashable type
```

Compare to this exception for **getitem** for the same thing:

``` python
>>> ts[:, 2]
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "pandas/core/series.py", line 944, in __getitem__
    return self._get_with(key)
  File "pandas/core/series.py", line 961, in _get_with
    return self._get_values_tuple(key)
  File "pandas/core/series.py", line 1007, in _get_values_tuple
    raise ValueError('Can only tuple-index with a MultiIndex')
ValueError: Can only tuple-index with a MultiIndex
```



Discussion:

Resolving patch:
diff --git a/pandas/core/series.py b/pandas/core/series.py
--- a/pandas/core/series.py
+++ b/pandas/core/series.py
@@ -1050,6 +1050,8 @@ def __setitem__(self, key, value):
             return
 
         except TypeError as e:
+            if isinstance(key, tuple) and not isinstance(self.index, MultiIndex):
+                raise ValueError("Can only tuple-index with a MultiIndex")
             # python 3 type errors should be raised
             if 'unorderable' in str(e):  # pragma: no cover
                 raise IndexError(key)


Test patch:
diff --git a/pandas/tests/test_series.py b/pandas/tests/test_series.py
--- a/pandas/tests/test_series.py
+++ b/pandas/tests/test_series.py
@@ -1025,10 +1025,10 @@ def test_setslice(self):
 
     def test_basic_getitem_setitem_corner(self):
         # invalid tuples, e.g. self.ts[:, None] vs. self.ts[:, 2]
-        self.assertRaises(Exception, self.ts.__getitem__,
-                          (slice(None, None), 2))
-        self.assertRaises(Exception, self.ts.__setitem__,
-                          (slice(None, None), 2), 2)
+        with tm.assertRaisesRegexp(ValueError, 'tuple-index'):
+            self.ts[:, 2]
+        with tm.assertRaisesRegexp(ValueError, 'tuple-index'):
+            self.ts[:, 2] = 2
 
         # weird lists. [slice(0, 5)] will work but not two slices
         result = self.ts[[slice(None, 5)]]
Repository: pandas-dev/pandas

Issue:
List of 0-dim np.ndarrays no longer works for DataFrame constructor
``` python
data = [np.array(x) for x in range(10)]
pd.DataFrame(data)

4814     else:
   4815         # last ditch effort
-> 4816         data = lmap(tuple, data)
   4817         return _list_to_arrays(data, columns,
   4818                                coerce_float=coerce_float,

TypeError: iteration over a 0-d array
```

Previously this case would fall through to `_prep_ndarray` but since `common.is_list_like` doesn't check that whether the `np.ndarray` is 0-dim, it incorrectly fails in `to_arrays`. 



Discussion:

Resolving patch:
diff --git a/pandas/core/frame.py b/pandas/core/frame.py
--- a/pandas/core/frame.py
+++ b/pandas/core/frame.py
@@ -429,7 +429,7 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
                 if index is None and isinstance(data[0], Series):
                     index = _get_names_from_index(data)
 
-                if is_list_like(data[0]) and getattr(data[0],'ndim',0) <= 1:
+                if is_list_like(data[0]) and getattr(data[0],'ndim',1) == 1:
                     arrays, columns = _to_arrays(data, columns, dtype=dtype)
                     columns = _ensure_index(columns)
 
@@ -4710,7 +4710,7 @@ def extract_index(data):
             elif isinstance(v, dict):
                 have_dicts = True
                 indexes.append(list(v.keys()))
-            elif is_list_like(v) and getattr(v,'ndim',0) <= 1:
+            elif is_list_like(v) and getattr(v,'ndim',1) == 1:
                 have_raw_arrays = True
                 raw_lengths.append(len(v))
 


Test patch:
diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py
--- a/pandas/tests/test_frame.py
+++ b/pandas/tests/test_frame.py
@@ -2675,6 +2675,13 @@ def test_constructor_list_of_lists(self):
         self.assert_(com.is_integer_dtype(df['num']))
         self.assert_(df['str'].dtype == np.object_)
 
+        # GH 4851
+        # list of 0-dim ndarrays
+        expected = DataFrame({ 0: range(10) })
+        data = [np.array(x) for x in range(10)]
+        result = DataFrame(data)
+        assert_frame_equal(result, expected)
+
     def test_constructor_sequence_like(self):
         # GH 3783
         # collections.Squence like
Repository: pandas-dev/pandas

Issue:
ValueError in HDFStore column append throws a TypeError
just needs to be stringified



Discussion:

Resolving patch:
diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py
--- a/pandas/io/pytables.py
+++ b/pandas/io/pytables.py
@@ -3033,7 +3033,9 @@ def create_axes(self, axes, obj, validate=True, nan_rep=None,
                     new_blocks.append(b)
                 except:
                     raise ValueError(
-                        "cannot match existing table structure for [%s] on appending data" % ','.join(items))
+                        "cannot match existing table structure for [%s] on "
+                        "appending data" % ','.join(com.pprint_thing(item) for
+                                                    item in items))
             blocks = new_blocks
 
         # add my values


Test patch:
diff --git a/pandas/io/tests/test_pytables.py b/pandas/io/tests/test_pytables.py
--- a/pandas/io/tests/test_pytables.py
+++ b/pandas/io/tests/test_pytables.py
@@ -3696,6 +3696,21 @@ def test_store_datetime_mixed(self):
 
     #    self.assertRaises(Exception, store.put, 'foo', df, format='table')
 
+    def test_append_with_diff_col_name_types_raises_value_error(self):
+        df = DataFrame(np.random.randn(10, 1))
+        df2 = DataFrame({'a': np.random.randn(10)})
+        df3 = DataFrame({(1, 2): np.random.randn(10)})
+        df4 = DataFrame({('1', 2): np.random.randn(10)})
+        df5 = DataFrame({('1', 2, object): np.random.randn(10)})
+
+        with ensure_clean('__%s__.h5' % tm.rands(20)) as store:
+            name = 'df_%s' % tm.rands(10)
+            store.append(name, df)
+
+            for d in (df2, df3, df4, df5):
+                with tm.assertRaises(ValueError):
+                    store.append(name, d)
+
 
 def _test_sort(obj):
     if isinstance(obj, DataFrame):
Repository: pandas-dev/pandas

Issue:
API: remove Factor
see #3603 deprecated in 0.11.1



Discussion:
@jseabold I believe slated to remove in 0.12....so remove for 0.13?


Resolving patch:
diff --git a/pandas/core/api.py b/pandas/core/api.py
--- a/pandas/core/api.py
+++ b/pandas/core/api.py
@@ -5,7 +5,7 @@
 
 from pandas.core.algorithms import factorize, match, unique, value_counts
 from pandas.core.common import isnull, notnull
-from pandas.core.categorical import Categorical, Factor
+from pandas.core.categorical import Categorical
 from pandas.core.format import (set_printoptions, reset_printoptions,
                                 set_eng_float_format)
 from pandas.core.index import Index, Int64Index, Float64Index, MultiIndex
diff --git a/pandas/core/categorical.py b/pandas/core/categorical.py
--- a/pandas/core/categorical.py
+++ b/pandas/core/categorical.py
@@ -230,16 +230,3 @@ def describe(self):
                                     counts=counts,
                                     freqs=freqs,
                                     levels=self.levels)).set_index('levels')
-
-
-class Factor(Categorical):
-    def __init__(self, labels, levels=None, name=None):
-        from warnings import warn
-        warn("Factor is deprecated. Use Categorical instead", FutureWarning)
-        super(Factor, self).__init__(labels, levels, name)
-
-    @classmethod
-    def from_array(cls, data):
-        from warnings import warn
-        warn("Factor is deprecated. Use Categorical instead", FutureWarning)
-        return super(Factor, cls).from_array(data)


Test patch:
Repository: pandas-dev/pandas

Issue:
ER: Uninformative error message when concat-ing Series with frames
```
In [164]: df = DataFrame(randn(10, 1))

In [165]: concat([df[0], df], axis=1)
```

throws an `AttributeError`. It should just say something about incompatible types in `concat`.

I wonder if it's worth allowing mixed types where it makes sense. E.g., `concat`-ing a `Series` and a `DataFrame`. It might be more consistent with the fact that `Series` is now an `NDFrame`.



Discussion:
want to do this for 0.13? if not pls change to 0.14

i got u covered


Resolving patch:
diff --git a/pandas/tools/merge.py b/pandas/tools/merge.py
--- a/pandas/tools/merge.py
+++ b/pandas/tools/merge.py
@@ -1245,7 +1245,11 @@ def _get_comb_axis(self, i):
         if self._is_series:
             all_indexes = [x.index for x in self.objs]
         else:
-            all_indexes = [x._data.axes[i] for x in self.objs]
+            try:
+                all_indexes = [x._data.axes[i] for x in self.objs]
+            except IndexError:
+                types = [type(x).__name__ for x in self.objs]
+                raise TypeError("Cannot concatenate list of %s" % types)
 
         return _get_combined_index(all_indexes, intersect=self.intersect)
 
@@ -1256,6 +1260,10 @@ def _get_concat_axis(self):
             elif self.keys is None:
                 names = []
                 for x in self.objs:
+                    if not isinstance(x, Series):
+                        raise TypeError("Cannot concatenate type 'Series' "
+                                        "with object of type "
+                                        "%r" % type(x).__name__)
                     if x.name is not None:
                         names.append(x.name)
                     else:


Test patch:
diff --git a/pandas/tools/tests/test_merge.py b/pandas/tools/tests/test_merge.py
--- a/pandas/tools/tests/test_merge.py
+++ b/pandas/tools/tests/test_merge.py
@@ -1804,6 +1804,15 @@ def test_concat_invalid_first_argument(self):
         # generator ok though
         concat(DataFrame(np.random.rand(5,5)) for _ in range(3))
 
+    def test_concat_mixed_types_fails(self):
+        df = DataFrame(randn(10, 1))
+
+        with tm.assertRaisesRegexp(TypeError, "Cannot concatenate.+"):
+            concat([df[0], df], axis=1)
+
+        with tm.assertRaisesRegexp(TypeError, "Cannot concatenate.+"):
+            concat([df, df[0]], axis=1)
+
 class TestOrderedMerge(unittest.TestCase):
 
     def setUp(self):
Repository: pandas-dev/pandas

Issue:
Period() docstring inconsistent with code when freq has a mult != 1
(I love Pandas!  Great work!  One small issue...)

The docstring for the `Period` constructor reads:

```
freq : str, default None
    e.g., 'B' for businessday, ('T', 5) or '5T' for 5 minutes
```

i.e. the docstring says that `freq` can be multiples of a period code (e.g. 5 minutes).

But if we try to use `mult != 1` then we get an exception:

``` Python
In [43]: pd.Period('2013-01-01', freq='5T')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-43-770fd8956b5c> in <module>()
----> 1 pd.Period('2013-01-01', freq='5T')

/usr/local/lib/python2.7/dist-packages/pandas/tseries/period.pyc in __init__(self, value, freq, ordinal, year, month, quarter, day, hour, minute, second)
    120         base, mult = _gfc(freq)
    121         if mult != 1:
--> 122             raise ValueError('Only mult == 1 supported')
    123 
    124         if self.ordinal is None:

ValueError: Only mult == 1 supported
```

This same error is given if we provide `freq` as a tuple like `freq=('T', 5)`

So either the code can't handle `mult != 1` (in which case the docstring is wrong). Or, if the docstring is _correct_ (the code _can_ handle a `mult != 1`) then the exception is wrong.

(For my own work, I would love to be able to use arbitrary-length `Period` instances.  Here's a related StackOverflow question that I have just asked: [Irregular, non-contiguous Periods in Pandas](http://stackoverflow.com/questions/18486106/irregular-non-contiguous-periods-in-pandas))

(I'm using Pandas 0.12)



Discussion:
@JackKelly PR for the doc change?


Resolving patch:
diff --git a/pandas/tseries/period.py b/pandas/tseries/period.py
--- a/pandas/tseries/period.py
+++ b/pandas/tseries/period.py
@@ -51,7 +51,7 @@ class Period(PandasObject):
     value : Period or compat.string_types, default None
         The time period represented (e.g., '4Q2005')
     freq : str, default None
-        e.g., 'B' for businessday, ('T', 5) or '5T' for 5 minutes
+        e.g., 'B' for businessday. Must be a singlular rule-code (e.g. 5T is not allowed).
     year : int, default None
     month : int, default 1
     quarter : int, default None


Test patch:
Repository: pandas-dev/pandas

Issue:
Remove internal classes from MultiIndex and Index pickles.
I added a FrozenNDArray and FrozenList class for MultiIndex internals for 0.13. They shouldn't end up in pickles, so we don't need to support them. Trivial fix but needs to happen before 0.13 is released.

Current less than optimal behavior:

```
In [2]: mi = MultiIndex.from_tuples(zip(range(10), range(10)))

In [3]: mi
Out[3]:
MultiIndex(levels=[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]
           labels=[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]])

In [4]: mi.__reduce__()
Out[4]:
(<function numpy.core.multiarray._reconstruct>,
 (pandas.core.index.MultiIndex, (0,), 'b'),
 ((1, (0,), dtype('O'), False, []),
  ([Int64Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=int64),
    Int64Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=int64)],
   [FrozenNDArray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=int64),
    FrozenNDArray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=int64)],
   None,
   [None, None])))
```

Correct output (or could just be ndarrays too):

```
In [2]: mi = MultiIndex.from_tuples(zip(range(10), range(10)))

In [3]: mi
Out[3]:
MultiIndex(levels=[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]
           labels=[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]])

In [4]: mi.__reduce__()
Out[4]:
(<function numpy.core.multiarray._reconstruct>,
 (pandas.core.index.MultiIndex, (0,), 'b'),
 ((1, (0,), dtype('O'), False, []),
  ([array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]),
    array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])],
   [array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]),
    array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])],
   None,
   [None, None])))
```



Discussion:

Resolving patch:
diff --git a/pandas/core/index.py b/pandas/core/index.py
--- a/pandas/core/index.py
+++ b/pandas/core/index.py
@@ -2458,8 +2458,9 @@ def __contains__(self, key):
     def __reduce__(self):
         """Necessary for making this object picklable"""
         object_state = list(np.ndarray.__reduce__(self))
-        subclass_state = (list(self.levels), list(
-            self.labels), self.sortorder, list(self.names))
+        subclass_state = ([lev.view(np.ndarray) for lev in self.levels],
+                          [label.view(np.ndarray) for label in self.labels],
+                          self.sortorder, list(self.names))
         object_state[2] = (object_state[2], subclass_state)
         return tuple(object_state)
 


Test patch:
Repository: pandas-dev/pandas

Issue:
BUG: Segfault on isnull(MultiIndex)
```
In [1]: from pandas import *

In [2]: idx = MultiIndex.from_tuples([(0, 'a'), (1, 'b'), (2, 'c')])

In [3]: pd.isnull(idx)
Segmentation fault: 11
(pandas-dev)dhcp80fff527:pandas tom$ 
```

This is on latest master (`'0.12.0-757-g69b67f3'`). Numpy 1.7.1.



Discussion:
FWIW, I'm not sure what I would expect this to return.  But probably not a segfault :)

I'm pretty sure I can fix it right now to not segfault - not really sure what it should return though.


Resolving patch:
diff --git a/pandas/core/common.py b/pandas/core/common.py
--- a/pandas/core/common.py
+++ b/pandas/core/common.py
@@ -12,6 +12,7 @@
 from numpy.lib.format import read_array, write_array
 import numpy as np
 
+import pandas as pd
 import pandas.algos as algos
 import pandas.lib as lib
 import pandas.tslib as tslib
@@ -116,8 +117,10 @@ def isnull(obj):
 def _isnull_new(obj):
     if lib.isscalar(obj):
         return lib.checknull(obj)
-
-    if isinstance(obj, (ABCSeries, np.ndarray)):
+    # hack (for now) because MI registers as ndarray
+    elif isinstance(obj, pd.MultiIndex):
+        raise NotImplementedError("isnull is not defined for MultiIndex")
+    elif isinstance(obj, (ABCSeries, np.ndarray)):
         return _isnull_ndarraylike(obj)
     elif isinstance(obj, ABCGeneric):
         return obj.apply(isnull)
@@ -141,8 +144,10 @@ def _isnull_old(obj):
     '''
     if lib.isscalar(obj):
         return lib.checknull_old(obj)
-
-    if isinstance(obj, (ABCSeries, np.ndarray)):
+    # hack (for now) because MI registers as ndarray
+    elif isinstance(obj, pd.MultiIndex):
+        raise NotImplementedError("isnull is not defined for MultiIndex")
+    elif isinstance(obj, (ABCSeries, np.ndarray)):
         return _isnull_ndarraylike_old(obj)
     elif isinstance(obj, ABCGeneric):
         return obj.apply(_isnull_old)


Test patch:
diff --git a/pandas/tests/test_index.py b/pandas/tests/test_index.py
--- a/pandas/tests/test_index.py
+++ b/pandas/tests/test_index.py
@@ -2314,6 +2314,13 @@ def test_slice_keep_name(self):
                                    names=['x', 'y'])
         self.assertEqual(x[1:].names, x.names)
 
+    def test_isnull_behavior(self):
+        # should not segfault GH5123
+        # NOTE: if MI representation changes, may make sense to allow
+        # isnull(MI)
+        with tm.assertRaises(NotImplementedError):
+            pd.isnull(self.index)
+
 
 def test_get_combined_index():
     from pandas.core.index import _get_combined_index
Repository: pandas-dev/pandas

Issue:
Fix unhelpful "length mismatch" error message on set_axis
When trying to change the columns of a DataFrame, I sometimes mess up the number of elements. I was getting this kind of message a few times too often.

```
>>> df = DataFrame({0:[1,2,3], 1:[1,2,3]})
>>> df.columns = df.columns = ['a', 'b', 'c']
Exception: Length mismatch (3 vs 2)
```

When the lists were bigger, I had to consult the source code or do some debugging to remember that the left side of the 'vs' is the length of the new column list.

So I wrote a fix...



Discussion:

Resolving patch:
diff --git a/pandas/core/internals.py b/pandas/core/internals.py
--- a/pandas/core/internals.py
+++ b/pandas/core/internals.py
@@ -1881,8 +1881,8 @@ def set_axis(self, axis, value, maybe_rename=True, check_axis=True):
         value = _ensure_index(value)
 
         if check_axis and len(value) != len(cur_axis):
-            raise ValueError('Length mismatch (%d vs %d)'
-                            % (len(value), len(cur_axis)))
+            raise ValueError('Length mismatch: Expected %d elements, got %d elements'
+                            % (len(cur_axis), len(value)))
 
         self.axes[axis] = value
         self._shape = None
@@ -3361,8 +3361,8 @@ def set_axis(self, axis, value):
         value = _ensure_index(value)
 
         if len(value) != len(cur_axis):
-            raise Exception('Length mismatch (%d vs %d)'
-                            % (len(value), len(cur_axis)))
+            raise ValueError('Length mismatch: Expected %d elements, got %d elements'
+                            % (len(cur_axis), len(value)))
         self.axes[axis] = value
         self._shape = None
         self._block.set_ref_items(self.items, maybe_rename=True)


Test patch: