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

Issue:
BUG: inferred_freq results in None with eastern hemisphere timezones
Closes #7310



Discussion:
nice! you are doing gr8 on the PR's. distinct independent issues with a test case and fix! keep it up!

thanks!


Resolving patch:
diff --git a/pandas/tseries/frequencies.py b/pandas/tseries/frequencies.py
--- a/pandas/tseries/frequencies.py
+++ b/pandas/tseries/frequencies.py
@@ -668,8 +668,12 @@ class _FrequencyInferer(object):
     def __init__(self, index, warn=True):
         self.index = index
         self.values = np.asarray(index).view('i8')
+
         if index.tz is not None:
-            self.values = tslib.date_normalize(self.values, index.tz)
+            f = lambda x: tslib.tz_convert_single(x, 'UTC', index.tz)
+            self.values = np.vectorize(f)(self.values)
+            # This cant work, because of DST
+            # self.values = tslib.tz_convert(self.values, 'UTC', index.tz)
 
         self.warn = warn
 


Test patch:
diff --git a/pandas/tseries/tests/test_frequencies.py b/pandas/tseries/tests/test_frequencies.py
--- a/pandas/tseries/tests/test_frequencies.py
+++ b/pandas/tseries/tests/test_frequencies.py
@@ -14,8 +14,7 @@
 import pandas.tseries.frequencies as fmod
 import pandas.tseries.offsets as offsets
 from pandas.tseries.period import PeriodIndex
-
-import pandas.lib as lib
+import pandas.compat as compat
 
 from pandas import _np_version_under1p7
 import pandas.util.testing as tm
@@ -258,19 +257,20 @@ def test_infer_freq(self):
 
     def test_infer_freq_tz(self):
 
+        freqs = {'AS-JAN': ['2009-01-01', '2010-01-01', '2011-01-01', '2012-01-01'],
+                 'Q-OCT': ['2009-01-31', '2009-04-30', '2009-07-31', '2009-10-31'],
+                 'M': ['2010-11-30', '2010-12-31', '2011-01-31', '2011-02-28'],
+                 'W-SAT': ['2010-12-25', '2011-01-01', '2011-01-08', '2011-01-15'],
+                 'D': ['2011-01-01', '2011-01-02', '2011-01-03', '2011-01-04'],
+                 'H': ['2011-12-31 22:00', '2011-12-31 23:00', '2012-01-01 00:00', '2012-01-01 01:00']
+        }
+
         # GH 7310
-        for tz in [None, 'Asia/Tokyo', 'US/Pacific', 'Europe/Paris']:
-            dates = ['2010-11-30', '2010-12-31', '2011-01-31', '2011-02-28']
-            idx = DatetimeIndex(dates)
-            self.assertEqual(idx.inferred_freq, 'M')
-
-            dates = ['2011-01-01', '2011-01-02', '2011-01-03', '2011-01-04']
-            idx = DatetimeIndex(dates)
-            self.assertEqual(idx.inferred_freq, 'D')
-
-            dates = ['2011-12-31 22:00', '2011-12-31 23:00', '2012-01-01 00:00', '2012-01-01 01:00']
-            idx = DatetimeIndex(dates)
-            self.assertEqual(idx.inferred_freq, 'H')
+        for tz in [None, 'Australia/Sydney', 'Asia/Tokyo', 'Europe/Paris',
+                   'US/Pacific', 'US/Eastern']:
+            for expected, dates in compat.iteritems(freqs):
+                idx = DatetimeIndex(dates, tz=tz)
+                self.assertEqual(idx.inferred_freq, expected)
 
     def test_not_monotonic(self):
         rng = _dti(['1/31/2000', '1/31/2001', '1/31/2002'])
Repository: pandas-dev/pandas

Issue:
TST: option retrieval failures
https://travis-ci.org/pydata/pandas/jobs/26755159

need a better skipping mechanism

```
======================================================================
ERROR: test_get_call_data_warning (pandas.io.tests.test_data.TestOptionsWarnings)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/virtualenv/python3.2.5/lib/python3.2/site-packages/pandas/util/testing.py", line 1281, in wrapper
    return t(*args, **kwargs)
  File "/home/travis/virtualenv/python3.2.5/lib/python3.2/site-packages/pandas/io/tests/test_data.py", line 341, in test_get_call_data_warning
    self.aapl.get_call_data(month=self.month, year=self.year)
  File "/home/travis/virtualenv/python3.2.5/lib/python3.2/site-packages/pandas/io/data.py", line 709, in get_call_data
    return self._get_option_data(month, year, expiry, 9, 'calls')
  File "/home/travis/virtualenv/python3.2.5/lib/python3.2/site-packages/pandas/io/data.py", line 669, in _get_option_data
    " found".format(table_loc, ntables))
IndexError: Table location 9 invalid, 0 tables found
----------------------------------------------------------------------
```



Discussion:
cc @dstephens99


Resolving patch:
diff --git a/pandas/io/data.py b/pandas/io/data.py
--- a/pandas/io/data.py
+++ b/pandas/io/data.py
@@ -664,7 +664,9 @@ def _get_option_data(self, month, year, expiry, table_loc, name):
                                       "element".format(url))
             tables = root.xpath('.//table')
             ntables = len(tables)
-            if table_loc - 1 > ntables:
+            if ntables == 0:
+                raise RemoteDataError("No tables found at {0!r}".format(url))
+            elif table_loc - 1 > ntables:
                 raise IndexError("Table location {0} invalid, {1} tables"
                                  " found".format(table_loc, ntables))
 


Test patch:
Repository: pandas-dev/pandas

Issue:
ix should return a Series on duplicate selection
see #7143 for an example.



Discussion:

Resolving patch:
diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py
--- a/pandas/core/indexing.py
+++ b/pandas/core/indexing.py
@@ -35,7 +35,6 @@ def __getitem__(self, arg):
 class IndexingError(Exception):
     pass
 
-
 class _NDFrameIndexer(object):
     _valid_types = None
     _exception = KeyError
@@ -61,7 +60,9 @@ def __iter__(self):
     def __getitem__(self, key):
         if type(key) is tuple:
             try:
-                return self.obj.get_value(*key)
+                values = self.obj.get_value(*key)
+                if np.isscalar(values):
+                    return values
             except Exception:
                 pass
 
@@ -1101,8 +1102,6 @@ class _IXIndexer(_NDFrameIndexer):
     """ A primarily location based indexer, with integer fallback """
 
     def _has_valid_type(self, key, axis):
-        ax = self.obj._get_axis(axis)
-
         if isinstance(key, slice):
             return True
 


Test patch:
diff --git a/pandas/tests/test_indexing.py b/pandas/tests/test_indexing.py
--- a/pandas/tests/test_indexing.py
+++ b/pandas/tests/test_indexing.py
@@ -3570,8 +3570,14 @@ def test_float_index_to_mixed(self):
                                          'a': [10] * 10}),
                               df)
 
+    def test_duplicate_ix_returns_series(self):
+        df = DataFrame(np.random.randn(3, 3), index=[0.1, 0.2, 0.2],
+                       columns=list('abc'))
+        r = df.ix[0.2, 'a']
+        e = df.loc[0.2, 'a']
+        tm.assert_series_equal(r, e)
+
 
 if __name__ == '__main__':
-    import nose
     nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
                    exit=False)
Repository: pandas-dev/pandas

Issue:
BUG: step with .loc on MultiIndex with list of indexers skips wrong elements
Setup (shared with #7399):

``` python
import pandas as pd
midx = pd.MultiIndex.from_product([range(5), ['a', 'b', 'c']])
s = pd.Series(range(15), midx)
print(s.loc[2:4:2, 'a':'c'])
```

What I get:

```
2  a     6
   c     8
3  b    10
4  a    12
   c    14
dtype: int64
```

What I expected (the step should only apply to the first level):

```
2  a     6
   b     7
   c     8
4  a    12
   b    13
   c    14
dtype: int64
```



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
@@ -3526,11 +3526,11 @@ def _get_level_indexer(self, key, level=0):
             # handle a slice, returnig a slice if we can
             # otherwise a boolean indexer
 
-            start = level_index.get_loc(key.start)
-            stop  = level_index.get_loc(key.stop)
+            start = level_index.get_loc(key.start or  0)
+            stop  = level_index.get_loc(key.stop or len(level_index)-1)
             step = key.step
 
-            if level > 0 or self.lexsort_depth == 0:
+            if level > 0 or self.lexsort_depth == 0 or step is not None:
                 # need to have like semantics here to right
                 # searching as when we are using a slice
                 # so include the stop+1 (so we include stop)


Test patch:
diff --git a/pandas/tests/test_indexing.py b/pandas/tests/test_indexing.py
--- a/pandas/tests/test_indexing.py
+++ b/pandas/tests/test_indexing.py
@@ -1325,6 +1325,29 @@ def test_loc_multiindex(self):
         result = df.loc[[1,2]]
         assert_frame_equal(result, expected)
 
+        # GH 7399
+        # incomplete indexers
+        s = pd.Series(np.arange(15,dtype='int64'),MultiIndex.from_product([range(5), ['a', 'b', 'c']]))
+        expected = s.loc[:, 'a':'c']
+
+        result = s.loc[0:4, 'a':'c']
+        assert_series_equal(result, expected)
+        assert_series_equal(result, expected)
+
+        result = s.loc[:4, 'a':'c']
+        assert_series_equal(result, expected)
+        assert_series_equal(result, expected)
+
+        result = s.loc[0:, 'a':'c']
+        assert_series_equal(result, expected)
+        assert_series_equal(result, expected)
+
+        # GH 7400
+        # multiindexer gettitem with list of indexers skips wrong element
+        s = pd.Series(np.arange(15,dtype='int64'),MultiIndex.from_product([range(5), ['a', 'b', 'c']]))
+        expected = s.iloc[[6,7,8,12,13,14]]
+        result = s.loc[2:4:2, 'a':'c']
+        assert_series_equal(result, expected)
 
     def test_series_getitem_multiindex(self):
Repository: pandas-dev/pandas

Issue:
BUG: nanops._maybe_null_out doesn't work with complex numbers
A number of nanops functions rely on the private internal function `nanops._maybe_null_out`.  These include `nansum`, `nanmin`, `nanmax`, and `nanprod`.  All of these, in principle, should work with arrays with a complex dtype.  However, due to a bug in `_maybe_null_out`, they convert the array to a float under certain situations, resulting in erroneous results.  The easiest way to trigger this is to have a complex array where all the imaginary values are nan, and make `axis` argument something other than `None`.

``` Python
>>> from pandas.core import nanops
>>> import bottleneck
>>> import numpy as np
>>> nanops._USE_BOTTLENECK = False
>>> 
>>> val = np.tile(1, (11, 7)) + np.tile(np.nan*1j, (11, 7))
>>> 
>>> bottleneck.nansum(val, axis=0)
array([ nan+0.j,  nan+0.j,  nan+0.j,  nan+0.j,  nan+0.j,  nan+0.j,  nan+0.j])
>>> nanops.nansum(val, axis=0)
array([ nan,  nan,  nan,  nan,  nan,  nan,  nan])
>>> bottleneck.nansum(val, axis=0).dtype
dtype('complex128')
>>> nanops.nansum(val, axis=0).dtype
dtype('float64')
```



Discussion:

Resolving patch:
diff --git a/pandas/core/nanops.py b/pandas/core/nanops.py
--- a/pandas/core/nanops.py
+++ b/pandas/core/nanops.py
@@ -547,7 +547,10 @@ def _maybe_null_out(result, axis, mask):
     if axis is not None:
         null_mask = (mask.shape[axis] - mask.sum(axis)) == 0
         if null_mask.any():
-            result = result.astype('f8')
+            if np.iscomplexobj(result):
+                result = result.astype('c16')
+            else:
+                result = result.astype('f8')
             result[null_mask] = np.nan
     else:
         null_mask = mask.size - mask.sum()


Test patch:
diff --git a/pandas/tests/test_nanops.py b/pandas/tests/test_nanops.py
--- a/pandas/tests/test_nanops.py
+++ b/pandas/tests/test_nanops.py
@@ -239,7 +239,6 @@ def test_nanall(self):
 
     def test_nansum(self):
         self.check_funs(nanops.nansum, np.sum,
-                        allow_complex=False,
                         allow_str=False, allow_date=False)
 
     def _nanmean_wrap(self, value, *args, **kwargs):
@@ -291,13 +290,11 @@ def _minmax_wrap(self, value, axis=None, func=None):
     def test_nanmin(self):
         func = partial(self._minmax_wrap, func=np.min)
         self.check_funs(nanops.nanmin, func,
-                        allow_complex=False,
                         allow_str=False, allow_obj=False)
 
     def test_nanmax(self):
         func = partial(self._minmax_wrap, func=np.max)
         self.check_funs(nanops.nanmax, func,
-                        allow_complex=False,
                         allow_str=False, allow_obj=False)
 
     def _argminmax_wrap(self, value, axis=None, func=None):
@@ -355,7 +352,6 @@ def test_nankurt(self):
 
     def test_nanprod(self):
         self.check_funs(nanops.nanprod, np.prod,
-                        allow_complex=False,
                         allow_str=False, allow_date=False)
 
     def check_nancorr_nancov_2d(self, checkfun, targ0, targ1, **kwargs):
Repository: pandas-dev/pandas

Issue:
Confusing error message on frame.__set_item__ with duplicate index entries
Struggled with this for a while to work out why I was getting `TypeError: incompatible index of inserted column with frame index` when doing df['new_col'] = my_series.

Turns out the the series had duplicates in its index. This occured because I was importing a CSV and then setting the index. Perhaps we need a warning when setting an index with duplicate values?

```
In [2]: df = pd.DataFrame({'foo':['a', 'b', 'c'], 'bar':[1,2,3], 'baz':['d','e','f']}).set_index('foo')

In [3]: df
Out[3]:
     bar baz
foo
a      1   d
b      2   e
c      3   f

[3 rows x 2 columns]

In [5]: ser = pd.DataFrame({'foo':['a', 'b', 'c', 'a'], 'fiz':['g','h','i','j']}).set_index('foo')

In [6]: ser
Out[6]:
    fiz
foo
a     g
b     h
c     i
a     j

[4 rows x 1 columns]
In [8]: df['newcol'] = ser
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-8-a8d535085de2> in <module>()
----> 1 df['newcol'] = ser

C:\WinPython-64bit-2.7.5.2\python-2.7.5.amd64\lib\site-packages\pandas-0.13.1-py2.7-win-amd64.egg\pandas\core\frame.pyc in __setitem__(self, key, value)
   1885         else:
   1886             # set column
-> 1887             self._set_item(key, value)
   1888
   1889     def _setitem_slice(self, key, value):

C:\WinPython-64bit-2.7.5.2\python-2.7.5.amd64\lib\site-packages\pandas-0.13.1-py2.7-win-amd64.egg\pandas\core\frame.pyc in _set_item(self, key, value)
   1965         is_existing = key in self.columns
   1966         self._ensure_valid_index(value)
-> 1967         value = self._sanitize_column(key, value)
   1968         NDFrame._set_item(self, key, value)
   1969

C:\WinPython-64bit-2.7.5.2\python-2.7.5.amd64\lib\site-packages\pandas-0.13.1-py2.7-win-amd64.egg\pandas\core\frame.pyc in _sanitize_column(self, key, value)
   2008                     value = value.reindex(self.index).values
   2009                 except:
-> 2010                     raise TypeError('incompatible index of inserted column '
   2011                                     'with frame index')
   2012

TypeError: incompatible index of inserted column with frame index
```



Discussion:
I would go for a slightly better error message here. pull-request?


Resolving patch:
diff --git a/pandas/core/frame.py b/pandas/core/frame.py
--- a/pandas/core/frame.py
+++ b/pandas/core/frame.py
@@ -1962,6 +1962,8 @@ def _sanitize_column(self, key, value):
                 # GH 4107
                 try:
                     value = value.reindex(self.index).values
+                except ValueError as e:
+                    raise e
                 except:
                     raise TypeError('incompatible index of inserted column '
                                     'with frame index')


Test patch:
Repository: pandas-dev/pandas

Issue:
Panel.apply fails when one of the axes is a Multi-Indexed DataFrame
Wrote up an example notebook:

http://nbviewer.ipython.org/urls/gist.githubusercontent.com/colindickson/850d3b5172f0320f204a/raw/62e4dfd450964326b8e3c2635c5c3f4c098a7352/panel.ipynb



Discussion:
hmm not really tested with multi index axes for panel - so a bug

what are u trying to do by unstacking?

maybe show what u want as an end result 

what i was orignally trying to do, was trying to do the equivalent of reconstructing a new panel with the unstacked dataframes.   

i've updated the notebook in the top post.

thanks!


Resolving patch:
diff --git a/pandas/tools/util.py b/pandas/tools/util.py
--- a/pandas/tools/util.py
+++ b/pandas/tools/util.py
@@ -3,6 +3,7 @@
 from pandas.core.index import Index
 import numpy as np
 from pandas import algos
+from pandas.core import common as com
 
 
 def match(needles, haystack):
@@ -32,7 +33,7 @@ def cartesian_product(X):
 
     b = cumprodX[-1] / cumprodX
 
-    return [np.tile(np.repeat(np.asarray(x), b[i]),
+    return [np.tile(np.repeat(np.asarray(com._values_from_object(x)), b[i]),
                     np.product(a[i]))
                for i, x in enumerate(X)]
 


Test patch:
diff --git a/pandas/tests/test_panel.py b/pandas/tests/test_panel.py
--- a/pandas/tests/test_panel.py
+++ b/pandas/tests/test_panel.py
@@ -1180,6 +1180,16 @@ def test_apply_slabs(self):
         expected = Panel(dict([ (ax,f(self.panel.loc[:,ax])) for ax in self.panel.major_axis ]))
         assert_panel_equal(result,expected)
 
+        # with multi-indexes
+        # GH7469
+        index = MultiIndex.from_tuples([('one', 'a'), ('one', 'b'), ('two', 'a'), ('two', 'b')])
+        dfa = DataFrame(np.array(np.arange(12, dtype='int64')).reshape(4,3), columns=list("ABC"), index=index)
+        dfb = DataFrame(np.array(np.arange(10, 22, dtype='int64')).reshape(4,3), columns=list("ABC"), index=index)
+        p = Panel({'f':dfa, 'g':dfb})
+        result = p.apply(lambda x: x.sum(), axis=0)
+        expected = p.sum(0)
+        assert_frame_equal(result,expected)
+
     def test_reindex(self):
         ref = self.panel['ItemB']
Repository: pandas-dev/pandas

Issue:
CLN: frame.py executable?
Somewhere along the way (3230ed4bd, I think) `frame.py` had its permissions changed, presumably by accident:

```
-rwxr-xr-x 1 dsm dsm 178861 Jun 21 09:51 pandas/core/frame.py
```



Discussion:

Resolving patch:
diff --git a/pandas/core/frame.py b/pandas/core/frame.py
old mode 100755
new mode 100644


Test patch:
Repository: pandas-dev/pandas

Issue:
BUG: Series.get w boolean accessor
from ML: https://groups.google.com/forum/#!topic/pydata/CDnF9cNR2ho

```
In [10]: df=pd.DataFrame({'i':[0]*10, 'b':[False]*10})

In [11]: vc_i=df.i.value_counts()

In [12]: vc_i.get(99,default='Missing')
Out[12]: 'Missing'

In [13]: vc_b=df.b.value_counts()

In [14]: vc_b
Out[14]: 
False    10
dtype: int64

In [15]: vc_b.get(False,default='Missing')
Out[15]: 10

In [16]: vc_b.get(True,default='Missing')

IndexError: index out of bounds
```



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
@@ -1191,7 +1191,7 @@ def get_value(self, series, key):
         try:
             return self._engine.get_value(s, k)
         except KeyError as e1:
-            if len(self) > 0 and self.inferred_type == 'integer':
+            if len(self) > 0 and self.inferred_type in ['integer','boolean']:
                 raise
 
             try:


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
@@ -123,6 +123,20 @@ def test_get(self):
         expected = 43
         self.assertEqual(result,expected)
 
+        # GH 7407
+        # with a boolean accessor
+        df = pd.DataFrame({'i':[0]*3, 'b':[False]*3})
+        vc = df.i.value_counts()
+        result = vc.get(99,default='Missing')
+        self.assertEquals(result,'Missing')
+
+        vc = df.b.value_counts()
+        result = vc.get(False,default='Missing')
+        self.assertEquals(result,3)
+
+        result = vc.get(True,default='Missing')
+        self.assertEquals(result,'Missing')
+
     def test_delitem(self):
 
         # GH 5542
Repository: pandas-dev/pandas

Issue:
BUG(?): get default value doesn't work for Series
`Series` have a `get` method, but using the default value doesn't work for certain type combinations:

```
>>> s = pd.Series([1,2,3], index=["a","b","c"])
>>> s
a    1
b    2
c    3
dtype: int64
>>> s.get("d", 0)
0
>>> s.get(10, 0)
Traceback (most recent call last):
  File "<ipython-input-18-26d73ac73179>", line 1, in <module>
    s.get(10, 0)
  File "/usr/local/lib/python2.7/dist-packages/pandas-0.14.0_421_g20dfc6b-py2.7-linux-x86_64.egg/pandas/core/generic.py", line 1040, in get
    return self[key]
  File "/usr/local/lib/python2.7/dist-packages/pandas-0.14.0_421_g20dfc6b-py2.7-linux-x86_64.egg/pandas/core/series.py", line 484, in __getitem__
    result = self.index.get_value(self, key)
  File "/usr/local/lib/python2.7/dist-packages/pandas-0.14.0_421_g20dfc6b-py2.7-linux-x86_64.egg/pandas/core/index.py", line 1202, in get_value
    return tslib.get_value_box(s, key)
  File "tslib.pyx", line 540, in pandas.tslib.get_value_box (pandas/tslib.c:11831)
  File "tslib.pyx", line 555, in pandas.tslib.get_value_box (pandas/tslib.c:11678)
IndexError: index out of bounds
```

I'm not sure whether it makes the most sense just to teach `.get` to catch IndexErrors as well as KeyErrors and ValueErrors (which is what it does now), or whether a deeper change is warranted.



Discussion:
I think could just catch the `IndexError` as well (or you can instead re-raise `TypeError` and return default on the catch-all). This is de-facto a wrapper around `__getitem__` (which on `TypeError` tries to figure things out).


Resolving patch:
diff --git a/pandas/core/generic.py b/pandas/core/generic.py
--- a/pandas/core/generic.py
+++ b/pandas/core/generic.py
@@ -1038,7 +1038,7 @@ def get(self, key, default=None):
         """
         try:
             return self[key]
-        except (KeyError, ValueError):
+        except (KeyError, ValueError, IndexError):
             return default
 
     def __getitem__(self, item):


Test patch:
diff --git a/pandas/tests/test_generic.py b/pandas/tests/test_generic.py
--- a/pandas/tests/test_generic.py
+++ b/pandas/tests/test_generic.py
@@ -123,6 +123,23 @@ def test_get_numeric_data(self):
 
         # _get_numeric_data is includes _get_bool_data, so can't test for non-inclusion
 
+    def test_get_default(self):
+        
+        # GH 7725
+        d0 = "a", "b", "c", "d"
+        d1 = np.arange(4, dtype='int64')
+        others = "e", 10
+        
+        for data, index in ((d0, d1), (d1, d0)):
+            s = Series(data, index=index)
+            for i,d in zip(index, data):
+                self.assertEqual(s.get(i), d)
+                self.assertEqual(s.get(i, d), d)
+                self.assertEqual(s.get(i, "z"), d)
+                for other in others:
+                    self.assertEqual(s.get(other, "z"), "z")
+                    self.assertEqual(s.get(other, other), other)
+
     def test_nonzero(self):
 
         # GH 4633