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

Issue:
BUG: inconsistency in some timedelta64[ns] reduction operations
```
In [1]: s = pd.to_timedelta(range(4),unit='d')

In [2]: s
Out[2]: 
0   0 days
1   1 days
2   2 days
3   3 days
dtype: timedelta64[ns]

In [3]: s.mean()
Out[3]: 
0   1 days, 12:00:00
dtype: timedelta64[ns]

In [4]: s.sum()
Out[4]: 518400000000000
```



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
@@ -231,7 +231,8 @@ def nansum(values, axis=None, skipna=True):
     values, mask, dtype = _get_values(values, skipna, 0)
     the_sum = values.sum(axis)
     the_sum = _maybe_null_out(the_sum, axis, mask)
-    return the_sum
+
+    return _wrap_results(the_sum, dtype)
 
 
 @disallow('M8')


Test patch:
diff --git a/pandas/tseries/tests/test_timedeltas.py b/pandas/tseries/tests/test_timedeltas.py
--- a/pandas/tseries/tests/test_timedeltas.py
+++ b/pandas/tseries/tests/test_timedeltas.py
@@ -207,6 +207,12 @@ def test_timedelta_ops(self):
         expected = to_timedelta('00:00:08')
         tm.assert_almost_equal(result, expected)
 
+        # GH 6462
+        # consistency in returned values for sum
+        result = td.sum()[0]
+        expected = to_timedelta('00:01:21')
+        tm.assert_almost_equal(result, expected)
+
     def test_to_timedelta_on_missing_values(self):
         _skip_if_numpy_not_friendly()
Repository: pandas-dev/pandas

Issue:
Resample with period='AS'/'A' does not work on localized indexes for multiple methods in "how"
I encountered a similar issue to (closed) #3592 .

When trying to resample a dataframe with a localized Datetime Index using the how method:

``` python
rng = pd.date_range('1/1/2011', periods=20000, freq='H')
rng = rng.tz_localize('EST')
ts = pd.DataFrame(index=rng)
ts['first']=np.random.randn(len(rng))
ts['second']=np.cumsum(np.random.randn(len(rng)))
ts2=ts.resample('A', how={'first':np.sum, 'second':np.mean})

*File "tslib.pyx", line 465, in pandas.tslib._Timestamp.__richcmp__ (pandas\tslib.c:9313)
*TypeError: can't compare offset-naive and offset-aware datetimes
```

For other (,lower) frequencies like "M" the same code works fine and if I just use 

```
how=np.mean
```

or just use 1 column in the dict

```
how={'first':np.mean}
```

it works too.

python 2.7.5
pandas 0.13.1

EDIT: Changed to include full example



Discussion:
can you provide the starting dataframe (code to recreate, doesn't have to be long), that reproduces this problem?

Changed the example so you can recreate it now!

If that means anything: with pandas 0.12 i get a TypeError, with pandas 0.13.1 it changed to ValueError (but the issue is the same).

gr8...thanks...will get to it for 0.14


Resolving patch:
diff --git a/pandas/tseries/index.py b/pandas/tseries/index.py
--- a/pandas/tseries/index.py
+++ b/pandas/tseries/index.py
@@ -1067,7 +1067,13 @@ def _can_fast_union(self, other):
         left_end = left[-1]
 
         # Only need to "adjoin", not overlap
-        return (right_start == left_end + offset) or right_start in left
+        try:
+            return (right_start == left_end + offset) or right_start in left
+        except (ValueError):
+
+            # if we are comparing an offset that does not propogate timezones
+            # this will raise
+            return False
 
     def _fast_union(self, other):
         if len(other) == 0:


Test patch:
diff --git a/pandas/tseries/tests/test_resample.py b/pandas/tseries/tests/test_resample.py
--- a/pandas/tseries/tests/test_resample.py
+++ b/pandas/tseries/tests/test_resample.py
@@ -973,6 +973,18 @@ def test_resample_tz_localized(self):
         expected = Series([1.5], index=ex_index)
         assert_series_equal(result, expected)
 
+        # GH 6397
+        # comparing an offset that doesn't propogate tz's
+        rng = date_range('1/1/2011', periods=20000, freq='H')
+        rng = rng.tz_localize('EST')
+        ts = DataFrame(index=rng)
+        ts['first']=np.random.randn(len(rng))
+        ts['second']=np.cumsum(np.random.randn(len(rng)))
+        expected = DataFrame({ 'first' : ts.resample('A',how=np.sum)['first'],
+                               'second' : ts.resample('A',how=np.mean)['second'] },columns=['first','second'])
+        result = ts.resample('A', how={'first':np.sum, 'second':np.mean}).reindex(columns=['first','second'])
+        assert_frame_equal(result,expected)
+
     def test_closed_left_corner(self):
         # #1465
         s = Series(np.random.randn(21),
Repository: pandas-dev/pandas

Issue:
BUG: algorithms._count_generic?
`algorithms._count_generic` returns a `Series` built from `counts`, which isn't defined:

```
def _count_generic(values, table_type, type_caster):
    from pandas.core.series import Series

    values = type_caster(values)
    table = table_type(min(len(values), 1000000))
    uniques, labels = table.factorize(values)

    return Series(counts, index=uniques)
```

but this function doesn't seem to be used anywhere.  The only reference I can find is in `algorithms.count`, or what would be `algorithms.count`, but that's commented out:

```
# def count(values, uniques=None):
#     f = lambda htype, caster: _count_generic(values, htype, caster)

#     if uniques is not None:
#         raise NotImplementedError
#     else:
#         return _hashtable_algo(f, values.dtype)
```



Discussion:
this I elieve was cythonized (as all the count function are)
in src/gererated.pyx

it's possible this is an older version

So would it be okay to remove both `_count_generic` and `#count` from algorithms as vestigial?

if they aren't referred and don't break any tests 
(it's possible they t not not tested I guess) so be careful 

@dsm054 can you do this when you have a chance? if nothng breaks when you remove

@dsm054 ?


Resolving patch:
diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py
--- a/pandas/core/algorithms.py
+++ b/pandas/core/algorithms.py
@@ -67,15 +67,6 @@ def unique(values):
     return _hashtable_algo(f, values.dtype)
 
 
-# def count(values, uniques=None):
-#     f = lambda htype, caster: _count_generic(values, htype, caster)
-
-#     if uniques is not None:
-#         raise NotImplementedError
-#     else:
-#         return _hashtable_algo(f, values.dtype)
-
-
 def _hashtable_algo(f, dtype):
     """
     f(HashTable, type_caster) -> result
@@ -88,16 +79,6 @@ def _hashtable_algo(f, dtype):
         return f(htable.PyObjectHashTable, com._ensure_object)
 
 
-def _count_generic(values, table_type, type_caster):
-    from pandas.core.series import Series
-
-    values = type_caster(values)
-    table = table_type(min(len(values), 1000000))
-    uniques, labels = table.factorize(values)
-
-    return Series(counts, index=uniques)
-
-
 def _match_generic(values, index, table_type, type_caster):
     values = type_caster(values)
     index = type_caster(index)


Test patch:
Repository: pandas-dev/pandas

Issue:
BUG: duplicate indexed assignement
from SO: http://stackoverflow.com/questions/22178642/assignment-modification-of-values-in-an-indexed-subframe-in-pandas

```
data = {'me':list('rttti'),'foo': list('aaade'), 'bar': arange(5)*1.34+2, 'bar2': arange(5)*-.34+2}
df = pd.DataFrame(data).set_index('me')

df.loc['r',['bar','bar2']]*=2.0
df.loc['t','bar']*=2.5
df.loc['t',['bar','bar2']]*=2.0
```



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
@@ -987,8 +987,13 @@ def intersection(self, other):
             except TypeError:
                 pass
 
-        indexer = self.get_indexer(other.values)
-        indexer = indexer.take((indexer != -1).nonzero()[0])
+        try:
+            indexer = self.get_indexer(other.values)
+            indexer = indexer.take((indexer != -1).nonzero()[0])
+        except:
+            # duplicates
+            indexer = self.get_indexer_non_unique(other.values)[0].unique()
+
         return self.take(indexer)
 
     def diff(self, other):
diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py
--- a/pandas/core/indexing.py
+++ b/pandas/core/indexing.py
@@ -441,7 +441,9 @@ def can_do_equal_len():
                         # align to
                         if item in value:
                             v = value[item]
-                            v = v.reindex(self.obj[item].index & v.index)
+                            i = self.obj[item].index
+                            v = v.reindex(i & v.index)
+
                             setter(item, v.values)
                         else:
                             setter(item, np.nan)


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
@@ -564,6 +564,29 @@ def test_loc_setitem(self):
         expected = DataFrame({'a' : [0.5,-0.5,-1.5], 'b' : [0,1,2] })
         assert_frame_equal(df,expected)
 
+    def test_loc_setitem_dups(self):
+
+        # GH 6541
+        df_orig = DataFrame({'me' : list('rttti'),
+                             'foo': list('aaade'),
+                             'bar': np.arange(5,dtype='float64')*1.34+2,
+                             'bar2': np.arange(5,dtype='float64')*-.34+2}).set_index('me')
+
+        indexer = tuple(['r',['bar','bar2']])
+        df = df_orig.copy()
+        df.loc[indexer]*=2.0
+        assert_series_equal(df.loc[indexer],2.0*df_orig.loc[indexer])
+
+        indexer = tuple(['r','bar'])
+        df = df_orig.copy()
+        df.loc[indexer]*=2.0
+        self.assertEqual(df.loc[indexer],2.0*df_orig.loc[indexer])
+
+        indexer = tuple(['t',['bar','bar2']])
+        df = df_orig.copy()
+        df.loc[indexer]*=2.0
+        assert_frame_equal(df.loc[indexer],2.0*df_orig.loc[indexer])
+
     def test_chained_getitem_with_lists(self):
 
         # GH6394
Repository: pandas-dev/pandas

Issue:
Series.quantile() should convert input dtype to float
Would love it if Series.quantile() converted the dtype to float (as DataFrame.quantile() appears to do). As it is, I get the following error with dtype=object:

```
In [8]: low
Out[8]: 
...
Name: p, Length: 2218, dtype: object

In [9]: low.quantile(0.33)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/ase/src/ase/analysis/conservation.py in <module>()
----> 1 low.quantile(0.33)

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/series.pyc in quantile(self, q)
   1323             return pa.NA
   1324         result = _quantile(valid_values, q * 100)
-> 1325         if result.dtype == _TD_DTYPE:
   1326             from pandas.tseries.timedeltas import to_timedelta
   1327             return to_timedelta(result)

AttributeError: 'float' object has no attribute 'dtype'
```



Discussion:
hmm...it shouldn't error like that. You should convert youself, `s.convert_objects()`

in general keeping things as object is not a good idea 


Resolving patch:
diff --git a/pandas/core/series.py b/pandas/core/series.py
--- a/pandas/core/series.py
+++ b/pandas/core/series.py
@@ -1287,7 +1287,7 @@ def quantile(self, q=0.5):
         if len(valid_values) == 0:
             return pa.NA
         result = _quantile(valid_values, q * 100)
-        if result.dtype == _TD_DTYPE:
+        if not np.isscalar and com.is_timedelta64_dtype(result):
             from pandas.tseries.timedeltas import to_timedelta
             return to_timedelta(result)
 


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
@@ -2102,6 +2102,10 @@ def test_quantile(self):
         q = self.ts.quantile(0.9)
         self.assertEqual(q, scoreatpercentile(self.ts.valid(), 90))
 
+        # object dtype
+        q = Series(self.ts,dtype=object).quantile(0.9)
+        self.assertEqual(q, scoreatpercentile(self.ts.valid(), 90))
+
     def test_describe(self):
         _ = self.series.describe()
         _ = self.ts.describe()
Repository: pandas-dev/pandas

Issue:
Series.pop() removes additional keys not specified
``` python
import pandas as pd
df = pd.DataFrame({
    'A': 0, 
    'B': range(5), 
    'C': 0, 
    })
k = df.iloc[4]
k.pop('B')
print k
```

```
out:
A    0
Name: 4, dtype: int64
```

```
expected:
A    0
C    0
Name: 4, dtype: int64

```

```
INSTALLED VERSIONS
------------------
commit: None
python: 2.7.4.final.0
python-bits: 64
OS: Linux
OS-release: 3.8.0-33-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: de_DE.UTF-8

pandas: 0.13.1
Cython: 0.17.4
numpy: 1.7.1
scipy: 0.11.0
statsmodels: 0.5.0
IPython: 0.13.2
sphinx: 1.1.3
patsy: 0.2.1
scikits.timeseries: None
dateutil: 1.5
pytz: 2012c
bottleneck: None
tables: 2.4.0
numexpr: 2.0.1
matplotlib: 1.2.1
openpyxl: 1.7.0
xlrd: 0.6.1
xlwt: 0.7.4
xlsxwriter: None
sqlalchemy: None
lxml: None
bs4: None
html5lib: None
bq: None
apiclient: None
```



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
@@ -3733,11 +3733,21 @@ def reindex_axis0_with_method(self, new_axis, indexer=None, method=None,
     def _delete_from_block(self, i, item):
         super(SingleBlockManager, self)._delete_from_block(i, item)
 
-        # reset our state
-        self._block = (
-            self.blocks[0] if len(self.blocks) else
-            make_block(np.array([], dtype=self._block.dtype), [], [])
-        )
+        # possibly need to merge split blocks
+        if len(self.blocks) > 1:
+            new_items = Index(list(itertools.chain(*[ b.items for b in self.blocks ])))
+            block = make_block(np.concatenate([ b.values for b in self.blocks ]),
+                               new_items,
+                               new_items,
+                               dtype=self._block.dtype)
+
+        elif len(self.blocks):
+            block = self.blocks[0]
+        else:
+            block = make_block(np.array([], dtype=self._block.dtype), [], [])
+
+        self.blocks = [block]
+        self._block = block
         self._values = self._block.values
 
     def get_slice(self, slobj):


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
@@ -710,6 +710,21 @@ def test_setindex(self):
     def test_array_finalize(self):
         pass
 
+    def test_pop(self):
+        # GH 6600
+        df = DataFrame({
+            'A': 0,
+            'B': np.arange(5,dtype='int64'),
+            'C': 0,
+            })
+        k = df.iloc[4]
+
+        result = k.pop('B')
+        self.assertEqual(result, 4)
+
+        expected = Series([0,0],index=['A','C'])
+        assert_series_equal(k, expected)
+
     def test_not_hashable(self):
         s_empty = Series()
         s = Series([1])
Repository: pandas-dev/pandas

Issue:
shift with named axis errors
```
df.shift(1, axis='columns')
# TypeError: tuple indices must be integers, not str
```

np.roll is being passed the original axis



Discussion:

Resolving patch:
diff --git a/pandas/core/generic.py b/pandas/core/generic.py
--- a/pandas/core/generic.py
+++ b/pandas/core/generic.py
@@ -3232,6 +3232,7 @@ def shift(self, periods=1, freq=None, axis=0, **kwds):
         if periods == 0:
             return self
 
+        axis = self._get_axis_number(axis)
         if freq is None and not len(kwds):
             new_data = self._data.shift(periods=periods, axis=axis)
         else:


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
@@ -5439,13 +5439,13 @@ def test_to_csv_deprecated_options(self):
             self.tsframe.to_csv(path, nanRep='foo')
             recons = read_csv(path,index_col=0,parse_dates=[0],na_values=['foo'])
             assert_frame_equal(self.tsframe, recons)
-        
+
         with tm.assert_produces_warning(FutureWarning):
             self.frame.to_csv(path, cols=['A', 'B'])
 
         with tm.assert_produces_warning(False):
             self.frame.to_csv(path, columns=['A', 'B'])
-            
+
 
     def test_to_csv_from_csv(self):
 
@@ -9194,6 +9194,12 @@ def test_shift(self):
         result = df.shift(1,axis=1)
         assert_frame_equal(result,expected)
 
+        # shift named axis
+        df = DataFrame(np.random.rand(10,5))
+        expected = pd.concat([DataFrame(np.nan,index=df.index,columns=[0]),df.iloc[:,0:-1]],ignore_index=True,axis=1)
+        result = df.shift(1,axis='columns')
+        assert_frame_equal(result,expected)
+
     def test_shift_bool(self):
         df = DataFrame({'high': [True, False],
                         'low': [False, False]})
@@ -9827,7 +9833,7 @@ def test_sort_nan(self):
         df = DataFrame({'A': [1, 2, nan, 1, 6, 8, 4],
                         'B': [9, nan, 5, 2, 5, 4, 5]},
                        index = [1, 2, 3, 4, 5, 6, nan])
-        
+
         # NaN label, ascending=True, na_position='last'
         sorted_df = df.sort(kind='quicksort', ascending=True, na_position='last')
         expected = DataFrame({'A': [1, 2, nan, 1, 6, 8, 4],
@@ -9884,7 +9890,7 @@ def test_stable_descending_multicolumn_sort(self):
         sorted_df = df.sort(['A','B'], ascending=[0,0], na_position='first',
                             kind='mergesort')
         assert_frame_equal(sorted_df, expected)
-        
+
     def test_sort_index_multicolumn(self):
         import random
         A = np.arange(5).repeat(20)
Repository: pandas-dev/pandas

Issue:
BUG: Series.iteritems() isn't lazy
The docstring indicates that it is supposed to be lazy, but we return `lzip(iter(self.index), iter(self))`. That should be `zip(...)` right? Or is the docstring wrong?



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
@@ -959,7 +959,7 @@ def iteritems(self):
         """
         Lazily iterate over (index, value) tuples
         """
-        return lzip(iter(self.index), iter(self))
+        return zip(iter(self.index), iter(self))
 
     if compat.PY3:  # pragma: no cover
         items = iteritems


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
@@ -1808,6 +1808,9 @@ def test_iteritems(self):
         for idx, val in compat.iteritems(self.ts):
             self.assertEqual(val, self.ts[idx])
 
+        # assert is lazy (genrators don't define __getslice__, lists do)
+        self.assertFalse(hasattr(self.series.iteritems(), '__getslice__'))
+
     def test_sum(self):
         self._check_stat_op('sum', np.sum)
Repository: pandas-dev/pandas

Issue:
DOC: DataFrame MERGE Example
In the Docstring for the **Merge** method, the example provided:

```
merge(A, B, left_on='lkey', right_on='rkey', how='outer')  
```

returns a _sorted_ DataFrame. Thus, we need to either add a **sort=True** _kwarg_ to the above code or replace the purported output with the actual (unsorted) output:

```
  lkey  value_x rkey  value_y
0  foo        1  foo        5
1  foo        4  foo        5
2  bar        2  bar        6
3  bar        2  bar        8
4  baz        3  NaN      NaN
5  NaN      NaN  qux        7
```



Discussion:
@SplashDance Thanks for the report! Would you like tro try to change this in the docstring (do a PR)? If you need some help with that, we would like to assist! (see here for some basic docs: http://pandas.pydata.org/developers.html#working-with-the-code)

For the basic example, I think it would be better to provide the actual output without the `sort` kwarg. (And BTW, edding the code to construct `A` and `B` would also be welcome).


Resolving patch:
diff --git a/pandas/core/frame.py b/pandas/core/frame.py
--- a/pandas/core/frame.py
+++ b/pandas/core/frame.py
@@ -123,11 +123,11 @@
 
 >>> merge(A, B, left_on='lkey', right_on='rkey', how='outer')
    lkey  value_x  rkey  value_y
-0  bar   2        bar   6
-1  bar   2        bar   8
-2  baz   3        NaN   NaN
-3  foo   1        foo   5
-4  foo   4        foo   5
+0  foo   1        foo   5
+1  foo   4        foo   5
+2  bar   2        bar   6
+3  bar   2        bar   8
+4  baz   3        NaN   NaN
 5  NaN   NaN      qux   7
 
 Returns


Test patch:
Repository: pandas-dev/pandas

Issue:
_reduce promotes numerics to strings when axis=0 and mixed type.
``` python
import pandas as pd
import numpy as np

df = pd.DataFrame({'num':[1,2,3], 'num2': np.random.randn(3), 'strings':list('abc')})
df.sum().values # array(['6', '-1.47818918058', 'abc'], dtype=object)
```

The issue is that axis=0 tries to coerce the dtypes and `np.array` will promote the numerics to strings. 

Note that:

``` python
df.T.sum(axis=1).values # array([6, -1.4781891805780178, 'abc'], dtype=object)
```

Maybe `com._coerce_to_dtypes` should just return the list?



Discussion:

Resolving patch:
diff --git a/pandas/core/common.py b/pandas/core/common.py
--- a/pandas/core/common.py
+++ b/pandas/core/common.py
@@ -840,6 +840,9 @@ def conv(r, dtype):
             elif dtype == _TD_DTYPE:
                 r = _coerce_scalar_to_timedelta_type(r)
             elif dtype == np.bool_:
+                # messy. non 0/1 integers do not get converted.
+                if is_integer(r) and r not in [0,1]:
+                    return int(r)
                 r = bool(r)
             elif dtype.kind == 'f':
                 r = float(r)
@@ -850,7 +853,7 @@ def conv(r, dtype):
 
         return r
 
-    return np.array([conv(r, dtype) for r, dtype in zip(result, dtypes)])
+    return [conv(r, dtype) for r, dtype in zip(result, dtypes)]
 
 
 def _infer_dtype_from_scalar(val):


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
@@ -10476,6 +10476,18 @@ def test_bool_describe_in_mixed_frame(self):
         assert_almost_equal(bool_describe['mean'], 0.4)
         assert_almost_equal(bool_describe['50%'], 0)
 
+    def test_reduce_mixed_frame(self):
+        # GH 6806
+        df = DataFrame({
+            'bool_data': [True, True, False, False, False],
+            'int_data': [10, 20, 30, 40, 50],
+            'string_data': ['a', 'b', 'c', 'd', 'e'],
+        })
+        df.reindex(columns=['bool_data', 'int_data', 'string_data'])
+        test = df.sum(axis=0)
+        assert_almost_equal(test.values, [2, 150, 'abcde'])
+        assert_series_equal(test, df.T.sum(axis=1))
+
     def test_count(self):
         f = lambda s: notnull(s).sum()
         self._check_stat_op('count', f,