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

Issue:
sets in str.cat?!
In #20347, I was asked to allow list-like inputs for the `.str.cat` methods for Series. However, I didn't know that `is_listlike({'a', 'b', 'c'})` is True (for sets) until I stumbled over it in #22486.

These objects should imo clearly be disallowed, lest users shoot themselves in the foot massively:
```
>>> s = pd.Series(['a', 'b', 'c'])
>>> s.str.cat({'a', 'b', 'c'})
0    ac
1    bb
2    ca
dtype: object
```

I'm not even sure this should go through a deprecation cycle - IMO it's just a plain ol' bug that should be fixed ASAP.


Discussion:
@h-vetinari There's definitely ways that this can misbehave, but the docstring for `is_listlike` shows using sets as an example, so it looks like it was intended?
@pambot 
There was time pressure for #20347 before `v0.23.0rc` and a few things did not get fully discussed. Had I known that `is_listlike(<set>) = True`, I would have excluded it specifically.

In fact, I'm struggling to think of a use-case in pandas where the order is irrelevant - it's a different (and larger) discussion whether that aspect of `is_listlike` should maybe be changed, but it should *definitely* be changed for `.str.cat`

Resolving patch:
diff --git a/pandas/core/strings.py b/pandas/core/strings.py
--- a/pandas/core/strings.py
+++ b/pandas/core/strings.py
@@ -1996,12 +1996,12 @@ def _get_series_list(self, others, ignore_index=False):
         elif isinstance(others, np.ndarray) and others.ndim == 2:
             others = DataFrame(others, index=idx)
             return ([others[x] for x in others], False)
-        elif is_list_like(others):
+        elif is_list_like(others, allow_sets=False):
             others = list(others)  # ensure iterators do not get read twice etc
 
             # in case of list-like `others`, all elements must be
             # either one-dimensional list-likes or scalars
-            if all(is_list_like(x) for x in others):
+            if all(is_list_like(x, allow_sets=False) for x in others):
                 los = []
                 join_warn = False
                 depr_warn = False


Test patch:
diff --git a/pandas/tests/test_strings.py b/pandas/tests/test_strings.py
--- a/pandas/tests/test_strings.py
+++ b/pandas/tests/test_strings.py
@@ -301,7 +301,17 @@ def test_str_cat_mixed_inputs(self, box):
         with tm.assert_raises_regex(TypeError, rgx):
             s.str.cat([u, [u, d]])
 
-        # forbidden input type, e.g. int
+        # forbidden input type: set
+        # GH 23009
+        with tm.assert_raises_regex(TypeError, rgx):
+            s.str.cat(set(u))
+
+        # forbidden input type: set in list
+        # GH 23009
+        with tm.assert_raises_regex(TypeError, rgx):
+            s.str.cat([u, set(u)])
+
+        # other forbidden input type, e.g. int
         with tm.assert_raises_regex(TypeError, rgx):
             s.str.cat(1)
Repository: pandas-dev/pandas

Issue:
Misleading "not" typo in assertion in pandas.concat in join_axes check
There is an assertion message in [concat.py](https://github.com/pandas-dev/pandas/blob/master/pandas/core/reshape/concat.py#L448):
```python

            if len(self.join_axes) != ndim - 1:
                raise AssertionError("length of join_axes must not be equal "
                                     "to {length}".format(length=ndim - 1))
```

From code (and from it's usage) it's obvious that word "**not**" is incorrect here and should be deleted.


Discussion:
Thanks for the report. Interested in submitting a PR fixing it?

Resolving patch:
diff --git a/pandas/core/reshape/concat.py b/pandas/core/reshape/concat.py
--- a/pandas/core/reshape/concat.py
+++ b/pandas/core/reshape/concat.py
@@ -446,7 +446,7 @@ def _get_new_axes(self):
                 new_axes[i] = self._get_comb_axis(i)
         else:
             if len(self.join_axes) != ndim - 1:
-                raise AssertionError("length of join_axes must not be equal "
+                raise AssertionError("length of join_axes must be equal "
                                      "to {length}".format(length=ndim - 1))
 
             # ufff...


Test patch:
Repository: pandas-dev/pandas

Issue:
pandas.MultiIndex.set_levels does not accept generator
#### Code Sample, a copy-pastable example if possible

```python
index = pd.MultiIndex.from_tuples(((0,1), (0, 2)))
index.set_levels(map(int, (3,)), level=0)
```
#### Problem description
Raises
```python
TypeError: 'map' object is not subscriptable
```
Workaround by wrapping map with list.

#### Expected Output
MultiIndex(levels=[[3], [1, 2]],
           labels=[[0, 0], [0, 1]])

#### Output of ``pd.show_versions()``

<details>
INSTALLED VERSIONS
------------------
commit: None
python: 3.6.6.final.0
python-bits: 64
OS: Linux
OS-release: 4.18.14-200.fc28.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.23.4
pytest: 3.8.2
pip: 10.0.1
setuptools: 40.4.3
Cython: None
numpy: 1.15.2
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 7.0.1
sphinx: 1.8.1
patsy: None
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.2.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
</details>



Discussion:
It's documented to accept a sequence, which needs to implement `__getitem__`. We would probably take a PR that turns the iterable into a list.

Resolving patch:
diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py
--- a/pandas/core/indexes/multi.py
+++ b/pandas/core/indexes/multi.py
@@ -389,6 +389,9 @@ def set_levels(self, levels, level=None, inplace=False,
                    labels=[[0, 0, 1, 1], [0, 1, 0, 1]],
                    names=[u'foo', u'bar'])
         """
+        if is_list_like(levels) and not isinstance(levels, Index):
+            levels = list(levels)
+
         if level is not None and not is_list_like(level):
             if not is_list_like(levels):
                 raise TypeError("Levels must be list-like")


Test patch:
diff --git a/pandas/tests/indexes/multi/test_get_set.py b/pandas/tests/indexes/multi/test_get_set.py
--- a/pandas/tests/indexes/multi/test_get_set.py
+++ b/pandas/tests/indexes/multi/test_get_set.py
@@ -414,3 +414,17 @@ def test_set_value_keeps_names():
     df.at[('grethe', '4'), 'one'] = 99.34
     assert df._is_copy is None
     assert df.index.names == ('Name', 'Number')
+
+
+def test_set_levels_with_iterable():
+    # GH23273
+    sizes = [1, 2, 3]
+    colors = ['black'] * 3
+    index = pd.MultiIndex.from_arrays([sizes, colors], names=['size', 'color'])
+
+    result = index.set_levels(map(int, ['3', '2', '1']), level='size')
+
+    expected_sizes = [3, 2, 1]
+    expected = pd.MultiIndex.from_arrays([expected_sizes, colors],
+                                         names=['size', 'color'])
+    tm.assert_index_equal(result, expected)
Repository: pandas-dev/pandas

Issue:
BUG: Setting timedelta column by index causes it to loss precision
#### Code Sample, a copy-pastable example if possible

```python
dt1 = pd.Timedelta(0)
dt2 = pd.Timedelta(28767471428571405)
df = pd.DataFrame({'dt': pd.Series([dt1, dt2])})
df_copy = df.copy()
s = pd.Series([dt1])

expected = df['dt'].iloc[1].value
df.loc[[True, False]] = s
result = df['dt'].iloc[1].value

print(result)
#28767471428571404
```
#### Problem description

Setting a timedelta column by index causes it to be casted to double and back. Therefore, it will loss precision.

#### Expected Output
28767471428571405

#### Output of ``pd.show_versions()``
0.23.4

<details>

[paste the output of ``pd.show_versions()`` here below this line]

</details>



Discussion:

Resolving patch:
diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py
--- a/pandas/core/internals/blocks.py
+++ b/pandas/core/internals/blocks.py
@@ -2104,9 +2104,9 @@ def _box_func(self):
     def _can_hold_element(self, element):
         tipo = maybe_infer_dtype_type(element)
         if tipo is not None:
-            return issubclass(tipo.type, np.timedelta64)
+            return issubclass(tipo.type, (np.timedelta64, np.int64))
         return is_integer(element) or isinstance(
-            element, (timedelta, np.timedelta64))
+            element, (timedelta, np.timedelta64, np.int64))
 
     def fillna(self, value, **kwargs):
 


Test patch:
diff --git a/pandas/tests/indexing/test_timedelta.py b/pandas/tests/indexing/test_timedelta.py
--- a/pandas/tests/indexing/test_timedelta.py
+++ b/pandas/tests/indexing/test_timedelta.py
@@ -80,3 +80,18 @@ def test_numpy_timedelta_scalar_indexing(self, start, stop,
         result = s.loc[slice(start, stop)]
         expected = s.iloc[expected_slice]
         tm.assert_series_equal(result, expected)
+
+    def test_roundtrip_thru_setitem(self):
+        # PR 23462
+        dt1 = pd.Timedelta(0)
+        dt2 = pd.Timedelta(28767471428571405)
+        df = pd.DataFrame({'dt': pd.Series([dt1, dt2])})
+        df_copy = df.copy()
+        s = pd.Series([dt1])
+
+        expected = df['dt'].iloc[1].value
+        df.loc[[True, False]] = s
+        result = df['dt'].iloc[1].value
+
+        assert expected == result
+        tm.assert_frame_equal(df, df_copy)
Repository: pandas-dev/pandas

Issue:
Can't put date in Series if index is a string longer than 1 character
#### Code Sample

```
>>> import pandas
>>> x = pandas.Series([1,2,3],  index=['Date','b','other'])
>>> x
Date     1
b        2
other    3
dtype: int64
>>> from datetime import date
>>> x.Date = date.today()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python37\lib\site-packages\pandas\core\generic.py", line 4405, in __setattr__
    self[name] = value
  File "C:\Python37\lib\site-packages\pandas\core\series.py", line 939, in __setitem__
    setitem(key, value)
  File "C:\Python37\lib\site-packages\pandas\core\series.py", line 935, in setitem
    self._set_with(key, value)
  File "C:\Python37\lib\site-packages\pandas\core\series.py", line 983, in _set_with
    self._set_labels(key, value)
  File "C:\Python37\lib\site-packages\pandas\core\series.py", line 993, in _set_labels
    raise ValueError('%s not contained in the index' % str(key[mask]))
ValueError: ['D' 'a' 't' 'e'] not contained in the index
>>> x.b = date.today()
>>> x.b
datetime.date(2018, 11, 1)
>>> x
Date              1
b        2018-11-01
other             3
dtype: object
>>>
```
#### Problem description

I cannot put a date object in a Series if the index is a string with len > 1.
It works if it's only a single character.  Other types seem to work.  I've only seen the problem with dates.



Discussion:
This looks similar to https://github.com/pandas-dev/pandas/issues/12862, and I can reproduce this in master as well.

Resolving patch:
diff --git a/pandas/core/series.py b/pandas/core/series.py
--- a/pandas/core/series.py
+++ b/pandas/core/series.py
@@ -947,7 +947,9 @@ def _set_with(self, key, value):
                 except Exception:
                     pass
 
-            if not isinstance(key, (list, Series, np.ndarray, Series)):
+            if is_scalar(key):
+                key = [key]
+            elif not isinstance(key, (list, Series, np.ndarray)):
                 try:
                     key = list(key)
                 except Exception:


Test patch:
diff --git a/pandas/tests/series/test_datetime_values.py b/pandas/tests/series/test_datetime_values.py
--- a/pandas/tests/series/test_datetime_values.py
+++ b/pandas/tests/series/test_datetime_values.py
@@ -548,3 +548,10 @@ def test_minmax_nat_series(self, nat):
     def test_minmax_nat_dataframe(self, nat):
         assert nat.min()[0] is pd.NaT
         assert nat.max()[0] is pd.NaT
+
+    def test_setitem_with_string_index(self):
+        # GH 23451
+        x = pd.Series([1, 2, 3], index=['Date', 'b', 'other'])
+        x['Date'] = date.today()
+        assert x.Date == date.today()
+        assert x['Date'] == date.today()
Repository: pandas-dev/pandas

Issue:
DOC: Validate space before colon in the parameters section of the docstrings
In the docstrings, parameters are documented like this:
```
Parameters
----------
name : str
    The name of the person.
```

It is common that the space before the colon is not present, and in that case `validate_docstrings.py` reports:
- `Parameter "name: str" has no type`

Which is confusing, and new contributors may have problems understanding what the problem is. We should validate this specific problem, and report an appropriate error message like `A space is required before the colon separating the parameter name and type`.

This needs to be tested (in `scripts/tests/test_validate_docstrings.py`).


Discussion:

Resolving patch:
diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py
--- a/scripts/validate_docstrings.py
+++ b/scripts/validate_docstrings.py
@@ -97,6 +97,8 @@
     'PR08': 'Parameter "{param_name}" description should start with a '
             'capital letter',
     'PR09': 'Parameter "{param_name}" description should finish with "."',
+    'PR10': 'Parameter "{param_name}" requires a space before the colon '
+            'separating the parameter name and type',
     'RT01': 'No Returns section found',
     'YD01': 'No Yields section found',
     'SA01': 'See Also section not found',
@@ -644,7 +646,11 @@ def validate_one(func_name):
     for param in doc.doc_parameters:
         if not param.startswith("*"):  # Check can ignore var / kwargs
             if not doc.parameter_type(param):
-                errs.append(error('PR04', param_name=param))
+                if ':' in param:
+                    errs.append(error('PR10',
+                                      param_name=param.split(':')[0]))
+                else:
+                    errs.append(error('PR04', param_name=param))
             else:
                 if doc.parameter_type(param)[-1] == '.':
                     errs.append(error('PR05', param_name=param))


Test patch:
diff --git a/scripts/tests/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py
--- a/scripts/tests/test_validate_docstrings.py
+++ b/scripts/tests/test_validate_docstrings.py
@@ -761,9 +761,8 @@ def test_bad_generic_functions(self, func):
         ('BadParameters', 'missing_params',
          ('Parameters {**kwargs} not documented',)),
         ('BadParameters', 'bad_colon_spacing',
-         ('Parameters {kind} not documented',
-          'Unknown parameters {kind: str}',
-          'Parameter "kind: str" has no type')),
+         ('Parameter "kind" requires a space before the colon '
+          'separating the parameter name and type',)),
         ('BadParameters', 'no_description_period',
          ('Parameter "kind" description should finish with "."',)),
         ('BadParameters', 'no_description_period_with_directive',
Repository: pandas-dev/pandas

Issue:
Update Index._values docstring for PeriodArray, IntervalArray
I’m pretty sure it’s out of date



Discussion:

Resolving patch:
diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py
--- a/pandas/core/indexes/base.py
+++ b/pandas/core/indexes/base.py
@@ -709,7 +709,7 @@ def values(self):
 
     @property
     def _values(self):
-        # type: () -> Union[ExtensionArray, Index]
+        # type: () -> Union[ExtensionArray, Index, np.ndarray]
         # TODO(EA): remove index types as they become extension arrays
         """The best array representation.
 
@@ -721,18 +721,14 @@ def _values(self):
 
         It may differ from the public '.values' method.
 
-        index             | values          | _values     | _ndarray_values |
-        ----------------- | -------------- -| ----------- | --------------- |
-        CategoricalIndex  | Categorical     | Categorical | codes           |
-        DatetimeIndex[tz] | ndarray[M8ns]   | DTI[tz]     | ndarray[M8ns]   |
-
-        For the following, the ``._values`` is currently ``ndarray[object]``,
-        but will soon be an ``ExtensionArray``
-
-        index             | values          | _values      | _ndarray_values |
-        ----------------- | --------------- | ------------ | --------------- |
-        PeriodIndex       | ndarray[object] | ndarray[obj] | ndarray[int]    |
-        IntervalIndex     | ndarray[object] | ndarray[obj] | ndarray[object] |
+        index             | values          | _values       | _ndarray_values |
+        ----------------- | --------------- | ------------- | --------------- |
+        Index             | ndarray         | ndarray       | ndarray         |
+        CategoricalIndex  | Categorical     | Categorical   | ndarray[int]    |
+        DatetimeIndex     | ndarray[M8ns]   | ndarray[M8ns] | ndarray[M8ns]   |
+        DatetimeIndex[tz] | ndarray[M8ns]   | DTI[tz]       | ndarray[M8ns]   |
+        PeriodIndex       | ndarray[object] | PeriodArray   | ndarray[int]    |
+        IntervalIndex     | IntervalArray   | IntervalArray | ndarray[object] |
 
         See Also
         --------


Test patch:
Repository: pandas-dev/pandas

Issue:
BUG: DataFrame.apply looses sparse dtype
```
In [151]: df = pd.SparseDataFrame(np.array([[0, 1, 0], [0, 0, 0], [0, 0, 1]]), 
                                  columns=['a', 'b', 'c'], default_fill_value=0)
In [152]: df2 = pd.DataFrame(df)

In [153]: df.apply(np.exp)['a']
Out[153]: 
0    1.0
1    1.0
2    1.0
Name: a, dtype: Sparse[float64, 1.0]
BlockIndex
Block locations: array([], dtype=int32)
Block lengths: array([], dtype=int32)

In [155]: df2.apply(np.exp)['a']
Out[155]: 
0    1.0
1    1.0
2    1.0
Name: a, dtype: float64
```


Discussion:
I observe the sparse dtype being lost after the copy, even before the apply

```
>>> df = pd.SparseDataFrame(np.array([[0, 1, 0], [0, 0, 0], [0, 0, 1]]), columns=list('abc'), default_fill_value=0)
>>> df2 = pd.DataFrame(df)
>>> type(df)
<class 'pandas.core.sparse.frame.SparseDataFrame'>
>>> type(df2)
<class 'pandas.core.frame.DataFrame'>
```

`df2 = pd.SparseDataFrame(df)` results in expected behaviour.
@JustinZhengBC The `pd.DataFrame(df)` instead of `pd.SparseDataFrame(df)` is on purpose, as I was testing the sparse support in a *normal* DataFrame. That was not fully clear from the issue.

Normal DataFrames also support storing sparse columns in it:

```
In [14]: type(df2)                                                                                                                                                              
Out[14]: pandas.core.frame.DataFrame

In [15]: df2.dtypes                                                                                                                                                             
Out[15]: 
a    Sparse[int64, 0]
b    Sparse[int64, 0]
c    Sparse[int64, 0]
dtype: object
```

Resolving patch:
diff --git a/pandas/core/apply.py b/pandas/core/apply.py
--- a/pandas/core/apply.py
+++ b/pandas/core/apply.py
@@ -132,7 +132,7 @@ def get_result(self):
         # ufunc
         elif isinstance(self.f, np.ufunc):
             with np.errstate(all='ignore'):
-                results = self.f(self.values)
+                results = self.obj._data.apply('apply', func=self.f)
             return self.obj._constructor(data=results, index=self.index,
                                          columns=self.columns, copy=False)
 


Test patch:
diff --git a/pandas/tests/sparse/frame/test_apply.py b/pandas/tests/sparse/frame/test_apply.py
--- a/pandas/tests/sparse/frame/test_apply.py
+++ b/pandas/tests/sparse/frame/test_apply.py
@@ -91,3 +91,14 @@ def test_applymap(frame):
     # just test that it works
     result = frame.applymap(lambda x: x * 2)
     assert isinstance(result, SparseDataFrame)
+
+
+def test_apply_keep_sparse_dtype():
+    # GH 23744
+    sdf = SparseDataFrame(np.array([[0, 1, 0], [0, 0, 0], [0, 0, 1]]),
+                          columns=['b', 'a', 'c'], default_fill_value=1)
+    df = DataFrame(sdf)
+
+    expected = sdf.apply(np.exp)
+    result = df.apply(np.exp)
+    tm.assert_frame_equal(expected, result)
Repository: pandas-dev/pandas

Issue:
equality comparison with a scalar is slow for category (performance regression)
Are the following 2 ways to compare a series to a scalar equivalent (ignore missing values)? I have to write the hard way in order to take advantage of the category properties.

    ```python
    x = pd.Series(list('abcd') * 1000000).astype('category')
    %timeit x == 'a'
    # 10 loops, best of 3: 25.2 ms per loop
    %timeit x.cat.codes == x.cat.categories.get_loc('a')
    # 1000 loops, best of 3: 750 µs per loop
    ```


Discussion:

Resolving patch:
diff --git a/asv_bench/benchmarks/categoricals.py b/asv_bench/benchmarks/categoricals.py
--- a/asv_bench/benchmarks/categoricals.py
+++ b/asv_bench/benchmarks/categoricals.py
@@ -46,6 +46,8 @@ def setup(self):
         self.values_some_nan = list(np.tile(self.categories + [np.nan], N))
         self.values_all_nan = [np.nan] * len(self.values)
         self.values_all_int8 = np.ones(N, 'int8')
+        self.categorical = pd.Categorical(self.values, self.categories)
+        self.series = pd.Series(self.categorical)
 
     def time_regular(self):
         pd.Categorical(self.values, self.categories)
@@ -68,6 +70,12 @@ def time_all_nan(self):
     def time_from_codes_all_int8(self):
         pd.Categorical.from_codes(self.values_all_int8, self.categories)
 
+    def time_existing_categorical(self):
+        pd.Categorical(self.categorical)
+
+    def time_existing_series(self):
+        pd.Categorical(self.series)
+
 
 class ValueCounts(object):
 
diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py
--- a/pandas/core/arrays/categorical.py
+++ b/pandas/core/arrays/categorical.py
@@ -347,6 +347,16 @@ def __init__(self, values, categories=None, ordered=None, dtype=None,
             # the "ordered" and "categories" arguments
             dtype = values.dtype._from_categorical_dtype(values.dtype,
                                                          categories, ordered)
+
+            # GH23814, for perf, if values._values already an instance of
+            # Categorical, set values to codes, and run fastpath
+            if (isinstance(values, (ABCSeries, ABCIndexClass)) and
+               isinstance(values._values, type(self))):
+                values = values._values.codes.copy()
+                if categories is None:
+                    categories = dtype.categories
+                fastpath = True
+
         else:
             # If dtype=None and values is not categorical, create a new dtype
             dtype = CategoricalDtype(categories, ordered)


Test patch: