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

Issue:
Use of deprecated `flask.ext.cors` results in a warning
``` python
In [1]: import blaze as bz
C:\Python\envs\py-dev\lib\site-packages\flask\exthook.py:71: ExtDeprecationWarning: Importing flask.ext.cors is deprecated, use flask_cors instead.
  .format(x=modname), ExtDeprecationWarning
```

Looks like the culprit is:
https://github.com/blaze/blaze/blob/bcddeba0230743d040bc915804af2ff906ce4758/blaze/server/server.py#L22



Discussion:

Resolving patch:
diff --git a/blaze/server/server.py b/blaze/server/server.py
--- a/blaze/server/server.py
+++ b/blaze/server/server.py
@@ -19,7 +19,7 @@
 from datashape import discover, pprint
 import flask
 from flask import Blueprint, Flask, Response
-from flask.ext.cors import cross_origin
+from flask_cors import cross_origin
 from werkzeug.http import parse_options_header
 from toolz import valmap, compose
 


Test patch:
diff --git a/blaze/server/tests/test_server.py b/blaze/server/tests/test_server.py
--- a/blaze/server/tests/test_server.py
+++ b/blaze/server/tests/test_server.py
@@ -2,7 +2,7 @@
 
 import pytest
 pytest.importorskip('flask')
-pytest.importorskip('flask.ext.cors')
+pytest.importorskip('flask_cors')
 
 from base64 import b64encode
 from copy import copy
Repository: python-geeks/Automation-scripts

Issue:
Tweet scrapper
## Script Title - A script that scrapes the tweets of a given user

**Brief** -
The script will be able to scrape the tweets of a specified user and then will be able to store them in a text file. I'd like to take this up!

## Instructions

- Create a new folder for your script and file/folder name should be appropriate.
- Create a README.md in your folder for program Instructions
- add requirements.txt if needed

### Programming Language

- [x] Python

Happy Coding



Discussion:

Resolving patch:
diff --git a/tweet_scraper/tweet_scraper.py b/tweet_scraper/tweet_scraper.py
new file mode 100644
--- /dev/null
+++ b/tweet_scraper/tweet_scraper.py
@@ -0,0 +1,32 @@
+import os
+import tweepy
+
+
+username = "saranshchopra7"    # edit the username here
+number_of_tweets = 100  # max can be 200
+
+# API keys
+CONSUMER_KEY = os.getenv("CONSUMER_KEY")
+CONSUMER_SECRET = os.getenv("CONSUMER_SECRET")
+ACCESS_TOKEN = os.getenv("ACCESS_TOKEN")
+ACCESS_TOKEN_SECRET = os.getenv("ACCESS_TOKEN_SECRET")
+
+# auth and API objects
+auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
+auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
+api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
+
+# scrape tweets
+tweets = api.user_timeline(
+    screen_name=username, count=number_of_tweets, tweet_mode="extended"
+)
+
+file = open("tweets.txt", "a", encoding="utf-8")
+
+# store the tweets
+for tweet in [tweet.full_text for tweet in tweets]:
+    file.write(
+        tweet + "\n===============================================================\n"
+    )
+
+file.close()


Test patch:
Repository: python-geeks/Automation-scripts

Issue:
Straighten image
## Script Title - A script to straighten up an image (for preprocessing purposes, can be used before OCRing an image)
**Brief** -
The script will basically rotate an image to straighten it up. Example (note that in the second image, the image has been tilted in a way that makes the book straight) - 

<p float="left">
<img src="https://user-images.githubusercontent.com/74055102/135614541-01f8ef65-de92-453b-b288-e81fa5dbe164.jpg" height=500/>
<img src="https://user-images.githubusercontent.com/74055102/135614855-b81844c7-d1fd-47f8-99fe-5141751abd7b.png" height=500/>
</p>

I'd like to take this up!

## Instructions

- Create a new folder for your script and file/folder name should be appropriate.
- Create a README.md in your folder for program Instructions
- add requirements.txt if needed

### Programming Language

- [x] Python

Happy Coding



Discussion:
Hi @kapshar, I am not a maintainer here. I am myself looking out to work on this issue :)
> I'd like to take this up!

Resolving patch:
diff --git a/straighten_image/straighten_image.py b/straighten_image/straighten_image.py
new file mode 100644
--- /dev/null
+++ b/straighten_image/straighten_image.py
@@ -0,0 +1,31 @@
+import cv2
+import math
+import numpy as np
+from scipy import ndimage
+
+
+path = "test.jpg"
+image = cv2.imread(path)
+image_edges = cv2.Canny(image, 100, 100, apertureSize=3)
+lines = cv2.HoughLinesP(
+    image_edges,
+    rho=1,
+    theta=np.pi / 180.0,
+    threshold=160,
+    minLineLength=100,
+    maxLineGap=10,
+)
+
+# calculate all the angles
+angles = []
+for [[x1, y1, x2, y2]] in lines:
+    # drawing Hough lines
+    angle = math.degrees(math.atan2(y2 - y1, x2 - x1))
+    angles.append(angle)
+
+# median of angles
+median_angle = np.median(angles)
+# rotate
+image = ndimage.rotate(image, median_angle)
+
+cv2.imwrite("rotated.png", image)


Test patch:
diff --git a/straighten_image/test.jpg b/straighten_image/test.jpg
new file mode 100644
Binary files /dev/null and b/straighten_image/test.jpg differ
Repository: python-geeks/Automation-scripts

Issue:
CSV to excel converter script
## Script Title - CSV to excel 

**Brief** - Aim to create Python script to convert the passed CSV file to excel in case of directory CSV inside the directory to be converted to excel.

## Instructions

- Create a new folder for your script and file/folder name should be appropriate.
- Create a README.md in your folder for program Instructions
- add requirements.txt if needed

### Programming Language

- [x] Python

Happy Coding



Discussion:

Resolving patch:
diff --git a/csv_to_excel/main.py b/csv_to_excel/main.py
new file mode 100644
--- /dev/null
+++ b/csv_to_excel/main.py
@@ -0,0 +1,35 @@
+import pandas as pd
+import sys
+import os
+
+args = sys.argv[1:]  # get command line *args
+assert args, "No file/dir was provided"  # raise error is no arg is passed
+
+isdir = os.path.isdir(args[-1])
+
+# If input is CSV file
+if not isdir:
+    assert args[-1].endswith(".csv"), "Input file is not CSV; Provide CSV file"
+    data = pd.read_csv(args[-1])  # load CSV data as Pd object
+    data.to_excel(args[-1][:-4] + ".xlsx", index=None, header=True)
+    del data
+
+# If input is Directory containing multiple csv
+else:
+    try:
+        # remove "/" from end of directory is passed
+        if args[-1][-1] == "/":
+            args[-1] = args[-1][:-1]
+        # create a dir to save the excel datasheet
+        os.mkdir(args[-1] + "_excel")
+    except Exception:
+        pass
+    for filename in os.listdir(args[-1]):
+        if filename.endswith(".csv"):
+            data = pd.read_csv(filename)
+            data.to_excel(
+                args[-1] + "_excel/" + filename[:-4] + ".xlsx"
+            )  # write as excel
+            del data  # delete the pandas DataFrame object
+
+exit(0)


Test patch:
Repository: python-geeks/Automation-scripts

Issue:
covid19_telegram_bot
##  covid19_telegram_bot

**Brief** - covid19_telegram_bot that posts real time covid19 updates to a telegram channel.
## Instructions

- I made a telegram bot that posts real time covid19 updates to a telegram channel. It updates the data from http://worldometers.info

- Please assign me to this Issue. Thank you.

### Programming Language

- [x] Python

Happy Coding



Discussion:

Resolving patch:
diff --git a/covid19_telegram_bot/covid19_telegram_bot.py b/covid19_telegram_bot/covid19_telegram_bot.py
new file mode 100644
--- /dev/null
+++ b/covid19_telegram_bot/covid19_telegram_bot.py
@@ -0,0 +1,53 @@
+"""
+Author: Shanmukha Vishnu
+Github: @iam-shanmukha
+"""
+import requests
+from covid import Covid
+
+previous_data = []
+# #######################Telegram###########################
+
+
+def send_msg(text):
+    token = "YOUR-TOKEN-HERE"
+    chat_id = "GROUP-CHAT-ID-HERE"
+    url_req = (
+        'https://api.telegram.org/'
+        'bot' + token + '/sendMessage' + '?chat_id'
+        '=' + chat_id + "&text=" + text)
+    results = requests.get(url_req)
+    print(results.json())
+
+
+# ##---One Time Run---###
+covid = Covid(source="worldometers")
+India_cases = covid.get_status_by_country_name("india")
+stat = (
+    "\n".join(
+        "{} : \t{}".format(k, v)
+        for k, v in India_cases.items()
+        if not k.startswith(("population", "total"))
+    )
+    + "\n#IndiaFightsCorona"
+)
+
+previous_data.append(stat)
+while 1:
+    covid = Covid(source="worldometers")
+    India_cases = covid.get_status_by_country_name("india")
+    stat = (
+        "\n".join(
+            "{} : \t{}".format(k, v)
+            for k, v in India_cases.items()
+            if not k.startswith(("population", "total"))
+        )
+        + "\n#IndiaFightsCorona"
+    )
+    if stat in previous_data:
+        print("Duplicate")
+    else:
+        print("msg _posted")
+        previous_data = []
+        previous_data.append(stat)
+        send_msg(stat)


Test patch:
Repository: python-geeks/Automation-scripts

Issue:
yaml_to_json add command line interface
**Describe the bug**
yaml_to_json currently only allow to enter filename. It is not convenient and cannot be used with bash autocomplete 

**To Reproduce**

**Expected behavior**
Application should accept command line arguments with filenames

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Additional context**
Add any other context about the problem here.


Discussion:

Resolving patch:
diff --git a/yaml_to_json/yaml_to_json.py b/yaml_to_json/yaml_to_json.py
--- a/yaml_to_json/yaml_to_json.py
+++ b/yaml_to_json/yaml_to_json.py
@@ -1,9 +1,11 @@
 from ruyaml import YAML
+import argparse
 import json
 
 
-def get_yaml_data():
-    yaml_name = input("Enter the yaml file name: ")
+def get_yaml_data(yaml_name=None):
+    if not yaml_name:
+        yaml_name = input("Enter the yaml file name: ")
 
     try:
         with open(yaml_name, "r+") as f:
@@ -14,18 +16,34 @@ def get_yaml_data():
         yaml_data = get_yaml_data()
 
 
-def convert_to_json(yaml_data):
-    json_name = input("Enter the name of output json file: ")
+def convert_to_json(yaml_data, json_name=None, intent=None):
+    if not json_name:
+        json_name = input("Enter the name of output json file: ")
 
     try:
         with open(json_name, "w+") as o:
-            o.write(json.dumps(yaml_data))
+            o.write(json.dumps(yaml_data, indent=intent))
     except:  # noqa
         print("Invalid input enter a valid json file name e.g. example.json")
         convert_to_json(yaml_data)
 
 
-yaml_data = get_yaml_data()
-convert_to_json(yaml_data)
+def main():
+    parser = argparse.ArgumentParser(description='Convert YAML file to JSON')
+    parser.add_argument('--yaml', type=str, help='YAML filename')
+    parser.add_argument('--json', type=str, help='JSON filename')
+    parser.add_argument('--intent', type=int, help="intent value for JSON")
+    args = parser.parse_args()
 
-print("Your yaml file has been converted and saved as json")
+    yaml_name = args.yaml
+    json_name = args.json
+    intent = args.intent
+
+    yaml_data = get_yaml_data(yaml_name)
+    convert_to_json(yaml_data, json_name, intent=intent)
+
+    print("Your yaml file has been converted and saved as json")
+
+
+if __name__ == "__main__":
+    main()


Test patch:
Repository: django-json-api/django-rest-framework-json-api

Issue:
DefaultRouter generated links need to conform to spec
Currently it still outputs the default:
![drf](https://cloud.githubusercontent.com/assets/322706/9262813/5db9400c-41dd-11e5-9973-c84c99777de1.png)



Discussion:

Resolving patch:
diff --git a/rest_framework_json_api/renderers.py b/rest_framework_json_api/renderers.py
--- a/rest_framework_json_api/renderers.py
+++ b/rest_framework_json_api/renderers.py
@@ -95,7 +95,12 @@ def render(self, data, accepted_media_type=None, renderer_context=None):
         if isinstance(data, dict) and data.get('links'):
             render_data['links'] = data.get('links')
 
-        render_data['data'] = json_api_data
+        # format the api root link list
+        if view.__class__ and view.__class__.__name__ == 'APIRoot':
+            render_data['data'] = None
+            render_data['links'] = json_api_data
+        else:
+            render_data['data'] = json_api_data
 
         if len(json_api_included) > 0:
             # Iterate through compound documents to remove duplicates


Test patch:
Repository: django-json-api/django-rest-framework-json-api

Issue:
ReadOnly fields are not rendered if their value is None
This is caused by a workaround added for the Browsable API https://github.com/django-json-api/django-rest-framework-json-api/commit/771ac1045826a55736f99934129b8b7ae8163e0f#commitcomment-14529488



Discussion:

Resolving patch:
diff --git a/rest_framework_json_api/utils.py b/rest_framework_json_api/utils.py
--- a/rest_framework_json_api/utils.py
+++ b/rest_framework_json_api/utils.py
@@ -239,10 +239,14 @@ def extract_attributes(fields, resource):
         if isinstance(field, (RelatedField, BaseSerializer, ManyRelatedField)):
             continue
 
-        # Skip read_only attribute fields when the resource is non-existent
-        # Needed for the "Raw data" form of the browseable API
-        if resource.get(field_name) is None and fields[field_name].read_only:
-            continue
+        # Skip read_only attribute fields when `resource` is an empty
+        # serializer. Prevents the "Raw Data" form of the browseable API
+        # from rendering `"foo": null` for read only fields
+        try:
+            resource[field_name]
+        except KeyError:
+            if fields[field_name].read_only:
+                continue
 
         data.update({
             field_name: resource.get(field_name)


Test patch:
diff --git a/example/tests/unit/test_utils.py b/example/tests/unit/test_utils.py
--- a/example/tests/unit/test_utils.py
+++ b/example/tests/unit/test_utils.py
@@ -111,6 +111,20 @@ def test_build_json_resource_obj():
     assert utils.build_json_resource_obj(
         serializer.fields, resource, resource_instance, 'user') == output
 
+def test_extract_attributes():
+    fields = {
+        'id': serializers.Field(),
+        'username': serializers.Field(),
+        'deleted': serializers.ReadOnlyField(),
+    }
+    resource = {'id': 1, 'deleted': None, 'username': 'jerel'}
+    expected = {
+        'username': 'jerel',
+        'deleted': None
+    }
+    assert sorted(utils.extract_attributes(fields, resource)) == sorted(expected), 'Regular fields should be extracted'
+    assert sorted(utils.extract_attributes(fields, {})) == sorted({'username': ''}), 'Should not extract read_only fields on empty serializer'
+
 
 class SerializerWithIncludedSerializers(EntrySerializer):
     included_serializers = {
Repository: django-json-api/django-rest-framework-json-api

Issue:
The get_resource_type_from_serializer bug
django-rest-framework-json-api v2.0.0-beta.2
I have defined `resource_name` attribute into Meta class of my serializer:

``` python
class MySerializer(serializers.Serializer):
    email = serializers.EmailField(required=True)
    class Meta:
        resource_name = 'user'
```

In this case the `get_resource_type_from_serializer` will always raise AttributeError, because there isn't defined the `model` attribute.
Code of `get_resource_type_from_serializer`:

``` python
def get_resource_type_from_serializer(serializer):
    return getattr(
        serializer.Meta,
        'resource_name',
        get_resource_type_from_model(serializer.Meta.model))
```



Discussion:

Resolving patch:
diff --git a/rest_framework_json_api/utils.py b/rest_framework_json_api/utils.py
--- a/rest_framework_json_api/utils.py
+++ b/rest_framework_json_api/utils.py
@@ -214,10 +214,10 @@ def get_resource_type_from_manager(manager):
 
 
 def get_resource_type_from_serializer(serializer):
-    return getattr(
-        serializer.Meta,
-        'resource_name',
-        get_resource_type_from_model(serializer.Meta.model))
+    if hasattr(serializer.Meta, 'resource_name'):
+        return serializer.Meta.resource_name
+    else:
+        return get_resource_type_from_model(serializer.Meta.model)
 
 
 def get_included_serializers(serializer):


Test patch:
diff --git a/example/tests/unit/test_utils.py b/example/tests/unit/test_utils.py
--- a/example/tests/unit/test_utils.py
+++ b/example/tests/unit/test_utils.py
@@ -15,6 +15,11 @@
 pytestmark = pytest.mark.django_db
 
 
+class NonModelResourceSerializer(serializers.Serializer):
+    class Meta:
+        resource_name = 'users'
+
+
 class ResourceSerializer(serializers.ModelSerializer):
     class Meta:
         fields = ('username',)
@@ -51,6 +56,11 @@ def test_get_resource_name():
     view.serializer_class.Meta.resource_name = 'rcustom'
     assert 'rcustom' == utils.get_resource_name(context), 'set on serializer'
 
+    view = GenericAPIView()
+    view.serializer_class = NonModelResourceSerializer
+    context = {'view': view}
+    assert 'users' == utils.get_resource_name(context), 'derived from non-model serializer'
+
 
 def test_format_keys():
     underscored = {
Repository: django-json-api/django-rest-framework-json-api

Issue:
field.related RemovedInDjango110Warning
This is likely an easy fix, I think the only tricky thing is making sure that this remains backwards compatible when making the change to field.remote_field.

This warning is seen using Django 1.9.

`rest_framework_json_api/utils.py:194: RemovedInDjango110Warning: Usage of field.related has been deprecated. Use field.remote_field instead.`

[Link to relevant line](https://github.com/django-json-api/django-rest-framework-json-api/blob/54f1dcd86bd571e83988c228e6ab3e3f72093d27/rest_framework_json_api/utils.py#L194)



Discussion:
👍 

Wrapping `field.remote_field` in a try/catch to fall back to `field.related` should be the right route forward on this if someone wants to tackle it


Resolving patch:
diff --git a/rest_framework_json_api/utils.py b/rest_framework_json_api/utils.py
--- a/rest_framework_json_api/utils.py
+++ b/rest_framework_json_api/utils.py
@@ -191,7 +191,10 @@ def get_related_resource_type(relation):
                 # Django 1.7
                 relation_model = parent_model_relation.related.model
         elif hasattr(parent_model_relation, 'field'):
-            relation_model = parent_model_relation.field.related.model
+            try:
+                relation_model = parent_model_relation.field.remote_field.model
+            except AttributeError:
+                relation_model = parent_model_relation.field.related.model
         else:
             return get_related_resource_type(parent_model_relation)
     return get_resource_type_from_model(relation_model)


Test patch:
Repository: django-json-api/django-rest-framework-json-api

Issue:
Add Django 1.11 LTS, DRF 3.5.x n 3.6.x releases to test matrix



Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -72,7 +72,7 @@ def get_package_data(package):
     version=get_version('rest_framework_json_api'),
     url='https://github.com/django-json-api/django-rest-framework-json-api',
     license='MIT',
-    description='A Django REST framework API adapter for the json-api spec.',
+    description='A Django REST framework API adapter for the JSON API spec.',
     long_description=read('README.rst'),
     author='Jerel Unruh',
     author_email='',
@@ -92,6 +92,7 @@ def get_package_data(package):
         'Programming Language :: Python :: 3.3',
         'Programming Language :: Python :: 3.4',
         'Programming Language :: Python :: 3.5',
+        'Programming Language :: Python :: 3.6',
         'Topic :: Internet :: WWW/HTTP',
         'Topic :: Software Development :: Libraries :: Application Frameworks',
         'Topic :: Software Development :: Libraries :: Python Modules',


Test patch:
Repository: django-json-api/django-rest-framework-json-api

Issue:
DRF 3.6.3 breaks tests
Looks like the latest DRF release broke some tests. See https://github.com/encode/django-rest-framework/pull/4222 for details.

Related breakage: https://travis-ci.org/django-json-api/django-rest-framework-json-api/jobs/233215665


Discussion:

Resolving patch:
diff --git a/example/serializers.py b/example/serializers.py
--- a/example/serializers.py
+++ b/example/serializers.py
@@ -37,12 +37,12 @@ class Meta:
 class EntrySerializer(serializers.ModelSerializer):
 
     def __init__(self, *args, **kwargs):
+        super(EntrySerializer, self).__init__(*args, **kwargs)
         # to make testing more concise we'll only output the
         # `featured` field when it's requested via `include`
         request = kwargs.get('context', {}).get('request')
         if request and 'featured' not in request.query_params.get('include', []):
-            self.fields.pop('featured')
-        super(EntrySerializer, self).__init__(*args, **kwargs)
+            self.fields.pop('featured', None)
 
     included_serializers = {
         'authors': 'example.serializers.AuthorSerializer',
diff --git a/rest_framework_json_api/serializers.py b/rest_framework_json_api/serializers.py
--- a/rest_framework_json_api/serializers.py
+++ b/rest_framework_json_api/serializers.py
@@ -50,6 +50,7 @@ def to_internal_value(self, data):
 
 class SparseFieldsetsMixin(object):
     def __init__(self, *args, **kwargs):
+        super(SparseFieldsetsMixin, self).__init__(*args, **kwargs)
         context = kwargs.get('context')
         request = context.get('request') if context else None
 
@@ -74,8 +75,6 @@ def __init__(self, *args, **kwargs):
                     if field_name not in fieldset:
                         self.fields.pop(field_name)
 
-        super(SparseFieldsetsMixin, self).__init__(*args, **kwargs)
-
 
 class IncludedResourcesValidationMixin(object):
     def __init__(self, *args, **kwargs):


Test patch:
Repository: django-json-api/django-rest-framework-json-api

Issue:
release 2.3.0?
It's in the changelog but it hasn't been released. Would you mind cutting a release for pypi? In particular the `Added nested included serializer support for remapped relations` is something we need.


Discussion:
I agree it would be great to have a new release. But I think at least PR https://github.com/django-json-api/django-rest-framework-json-api/pull/376 needs to be merged as otherwise backwards compatibility is broken.

Also ideal would be to merge https://github.com/django-json-api/django-rest-framework-json-api/pull/374 as well.
I just merged #376. I've not done a release for DJA before, but I now have the upload permissions. When I have some time, I'll try to put out a release.

Resolving patch:
diff --git a/rest_framework_json_api/__init__.py b/rest_framework_json_api/__init__.py
--- a/rest_framework_json_api/__init__.py
+++ b/rest_framework_json_api/__init__.py
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 
 __title__ = 'djangorestframework-jsonapi'
-__version__ = '2.2.0'
+__version__ = '2.3.0'
 __author__ = ''
 __license__ = 'MIT'
 __copyright__ = ''


Test patch:
Repository: django-json-api/django-rest-framework-json-api

Issue:
Test with tox in CI
2.3.0 is currently broken unless a user's environment happens to have `six` installed. If the CI tests ran at least one test that minimally installs the package and runs some basic tests to import things, then that kind of problem would be avoided.


Discussion:
Maybe we could use https://pypi.org/project/tox-travis/

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -108,6 +108,7 @@ def get_package_data(package):
         'factory-boy',
         'pytest-django',
         'pytest',
+        'pytest-cov',
         'django-polymorphic>=2.0',
         'packaging',
         'django-debug-toolbar'


Test patch: