nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: joke2k/faker
Pull request #1431 (2021-04-22 06:28:12)

Add tlds for th_TH internet provider
### What does this changes

- Add `tlds` for th_TH, in internet provider

### What was wrong

Internet provider previously not has th_TH locale

### How this fixes it

Add user name formats and TLDs for th_TH 


bact: I will add the test.

Patch:
diff --git a/faker/providers/internet/th_TH/__init__.py b/faker/providers/internet/th_TH/__init__.py
new file mode 100644
index 00000000..229ff5e3
--- /dev/null
+++ b/faker/providers/internet/th_TH/__init__.py
@@ -0,0 +1,32 @@
+from collections import OrderedDict
+
+from .. import Provider as InternetProvider
+
+
+class Provider(InternetProvider):
+    free_email_domains = (
+        "hotmail.com",
+        "gmail.com",
+        "outlook.com",
+        "yahoo.com",
+        "ymail.com",
+        "kon.in.th",
+        "icloud.com",
+        "protonmail.com",
+    )
+
+    tlds = OrderedDict(
+        (
+            ("in.th", 100),
+            ("co.th", 80),
+            ("go.th", 40),
+            ("or.th", 40),
+            ("ac.th", 20),
+            ("net.th", 10),
+            ("mi.th", 5),
+            ("co", 10),
+            ("net", 20),
+            ("com", 150),
+            ("org", 50),
+        ),
+    )
diff --git a/faker/providers/person/th_TH/__init__.py b/faker/providers/person/th_TH/__init__.py
index 0f8aacf0..3a3f9c84 100644
--- a/faker/providers/person/th_TH/__init__.py
+++ b/faker/providers/person/th_TH/__init__.py
@@ -804,7 +804,7 @@ class Provider(PersonProvider):
         "ถนัดภาษา",
         "ถนัดรบ",
         "ถนัดรักษา",
-        "ถนัดหัดถกรรม",
+        "ถนัดหัตถกรรม",
         "ถนัดอักษร",
         "ถนัดอาวุธ",
         "ถนิมมาศ",


Test patch:
diff --git a/tests/providers/test_internet.py b/tests/providers/test_internet.py
index b2db5731..11b4df51 100644
--- a/tests/providers/test_internet.py
+++ b/tests/providers/test_internet.py
@@ -14,6 +14,7 @@ from faker.providers.internet.en_GB import Provider as EnGbInternetProvider
 from faker.providers.internet.es_ES import Provider as EsEsInternetProvider
 from faker.providers.internet.pl_PL import Provider as PlPlInternetProvider
 from faker.providers.internet.ro_RO import Provider as RoRoInternetProvider
+from faker.providers.internet.th_TH import Provider as ThThInternetProvider
 from faker.providers.internet.zh_CN import Provider as ZhCnInternetProvider
 from faker.providers.person.ja_JP import Provider as JaPersonProvider
 from faker.utils import text
@@ -664,3 +665,11 @@ class TestRoRo:
     def test_tld(self, faker):
         tld = faker.tld()
         assert tld in PlPlInternetProvider.tlds
+
+
+class TestThTh:
+    """Test th_TH internet provider methods"""
+
+    def test_tld(self, faker):
+        tld = faker.tld()
+        assert tld in ThThInternetProvider.tlds
Repository: joke2k/faker
Pull request #1464 (2021-06-12 11:14:38)

Add IANA Registrar ID
### What does this changes

Add IANA Registrar ID generator


fcurella: Thank you!

Patch:
diff --git a/faker/providers/internet/__init__.py b/faker/providers/internet/__init__.py
index eed6bf67..705ffc59 100644
--- a/faker/providers/internet/__init__.py
+++ b/faker/providers/internet/__init__.py
@@ -563,3 +563,12 @@ class Provider(BaseProvider):
         height_ = height or self.random_int(max=1024)
         placeholder_url = self.random_element(self.image_placeholder_services)
         return placeholder_url.format(width=width_, height=height_)
+
+    def iana_id(self):
+        """Returns IANA Registrar ID
+        https://www.iana.org/assignments/registrar-ids/registrar-ids.xhtml
+
+        :rtype: str
+        """
+
+        return str(self.random_int(min=1, max=8888888))


Test patch:
diff --git a/tests/providers/test_internet.py b/tests/providers/test_internet.py
index 11b4df51..da7b06a0 100644
--- a/tests/providers/test_internet.py
+++ b/tests/providers/test_internet.py
@@ -304,6 +304,10 @@ class TestInternetProvider:
         expected_domain = 'cqphixmpdfpptskr.com'
         assert faker.dga(day=1, month=1, year=1000, tld='com', length=16) == expected_domain
 
+    def test_iana_id(self, faker, num_samples):
+        for _ in range(num_samples):
+            assert 1 <= int(faker.iana_id()) <= 8888888
+
 
 class TestInternetProviderUrl:
     """ Test internet url generation """
Repository: joke2k/faker
Pull request #1473 (2021-06-27 09:43:09)

Add RIPE ID
### What does this changes

Add RIPE Organization ID generator


fcurella: Thank you!

Patch:
diff --git a/faker/providers/internet/__init__.py b/faker/providers/internet/__init__.py
index 705ffc59..5cea954b 100644
--- a/faker/providers/internet/__init__.py
+++ b/faker/providers/internet/__init__.py
@@ -572,3 +572,14 @@ class Provider(BaseProvider):
         """
 
         return str(self.random_int(min=1, max=8888888))
+
+    def ripe_id(self):
+        """Returns RIPE Organization ID
+        https://www.ripe.net/manage-ips-and-asns/db/support/organisation-object-in-the-ripe-database
+
+        :rtype: str
+        """
+
+        lex = '?' * self.random_int(min=2, max=4)
+        num = '%' * self.random_int(min=1, max=5)
+        return self.bothify(f'ORG-{lex}{num}-RIPE').upper()


Test patch:
diff --git a/tests/providers/test_internet.py b/tests/providers/test_internet.py
index da7b06a0..f62b803b 100644
--- a/tests/providers/test_internet.py
+++ b/tests/providers/test_internet.py
@@ -308,6 +308,11 @@ class TestInternetProvider:
         for _ in range(num_samples):
             assert 1 <= int(faker.iana_id()) <= 8888888
 
+    def test_ripe_id(self, faker, num_samples):
+        pattern = re.compile(r'^ORG-[A-Z]{2,4}[1-9]\d{0,4}-RIPE$')
+        for _ in range(num_samples):
+            assert pattern.fullmatch(faker.ripe_id())
+
 
 class TestInternetProviderUrl:
     """ Test internet url generation """
Repository: joke2k/faker
Pull request #1485 (2021-07-22 20:20:11)

Return list instead of tuple in choices_distribution
### What does this changes

This is a proposed fix for https://github.com/joke2k/faker/issues/1484.

It appears this line has come up in the past: https://github.com/joke2k/faker/issues/1367#issuecomment-758345350 and https://github.com/joke2k/faker/pull/1368#pullrequestreview-566519393.

### What was wrong

We should not return a list here as that type is not the same as what `random.choices` (below it) would return (assuming the default implementation in the standard library). The `else` part below it also uses a `choices` list to return at the end.

### How this fixes it

This adds a test case for `random_letters` in general and it specifically asserts that the return value is a `list`, as mentioned in the docstring of `random_letters()`.


fcurella: Thank you!

Patch:
diff --git a/faker/utils/distribution.py b/faker/utils/distribution.py
index 64cc2e08..93b133d4 100644
--- a/faker/utils/distribution.py
+++ b/faker/utils/distribution.py
@@ -61,7 +61,7 @@ def choices_distribution(
 
     if hasattr(random, 'choices'):
         if length == 1 and p is None:
-            return (random.choice(a),)
+            return [random.choice(a)]
         else:
             return random.choices(a, weights=p, k=length)
     else:


Test patch:
diff --git a/tests/providers/__init__.py b/tests/providers/__init__.py
index 23816985..af1f6767 100644
--- a/tests/providers/__init__.py
+++ b/tests/providers/__init__.py
@@ -152,6 +152,16 @@ class TestBaseProvider:
             letter = faker.random_letter()
             assert letter.isalpha()
 
+    @pytest.mark.parametrize('length', [0, 1, 2], ids=[
+        'empty_list', 'list_with_one_element', 'list_with_two_elements',
+    ])
+    def test_random_letters(self, faker, length):
+        letters = faker.random_letters(length=length)
+        assert len(letters) == length
+        assert isinstance(letters, list)
+        for letter in letters:
+            assert letter.isalpha()
+
     def test_random_lowercase_letter(self, faker, num_samples):
         for _ in range(num_samples):
             letter = faker.random_lowercase_letter()
Repository: joke2k/faker
Pull request #1490 (2021-07-30 06:00:38)

Add NIC Handle ID
### What does this changes

Adds NIC Handle ID


fcurella: Thank you!

Patch:
diff --git a/faker/providers/internet/__init__.py b/faker/providers/internet/__init__.py
index 5cea954b..f5ebc38b 100644
--- a/faker/providers/internet/__init__.py
+++ b/faker/providers/internet/__init__.py
@@ -583,3 +583,25 @@ class Provider(BaseProvider):
         lex = '?' * self.random_int(min=2, max=4)
         num = '%' * self.random_int(min=1, max=5)
         return self.bothify(f'ORG-{lex}{num}-RIPE').upper()
+
+    def nic_handle(self, suffix='FAKE'):
+        """Returns NIC Handle ID
+        https://www.apnic.net/manage-ip/using-whois/guide/person/
+
+        :rtype: str
+        """
+
+        if len(suffix) < 2:
+            raise ValueError('suffix length must be greater than or equal to 2')
+
+        lex = '?' * self.random_int(min=2, max=4)
+        num = '%' * self.random_int(min=1, max=5)
+        return self.bothify(f'{lex}{num}-{suffix}').upper()
+
+    def nic_handles(self, count=1, suffix='????'):
+        """Returns NIC Handle ID list
+
+        :rtype: list[str]
+        """
+
+        return [self.nic_handle(suffix=suffix) for _ in range(count)]


Test patch:
diff --git a/tests/providers/test_internet.py b/tests/providers/test_internet.py
index f62b803b..356572c1 100644
--- a/tests/providers/test_internet.py
+++ b/tests/providers/test_internet.py
@@ -313,6 +313,21 @@ class TestInternetProvider:
         for _ in range(num_samples):
             assert pattern.fullmatch(faker.ripe_id())
 
+    def test_nic_handles(self, faker, num_samples):
+        pattern = re.compile(r'^[A-Z]{2,4}[1-9]\d{0,4}-[A-Z]*')
+        for _ in range(num_samples):
+            nhs = faker.nic_handles()
+            for nh in nhs:
+                assert pattern.fullmatch(nh)
+
+        nhs = faker.nic_handles(suffix='??', count=num_samples)
+        assert len(nhs) == num_samples
+        for nh in nhs:
+            assert pattern.fullmatch(nh)
+
+        with pytest.raises(ValueError):
+            faker.nic_handles(suffix='')
+
 
 class TestInternetProviderUrl:
     """ Test internet url generation """
Repository: joke2k/faker
Pull request #1497 (2021-08-20 04:15:39)

Added currency formats in pt_BR
### What does this changes
Added currency formats in pt_BR

### What was wrong
Did not exist

### How this fixes it
Added new folder in currency/pt_BR and new file __init__.py and added tests for this.


fcurella: Thank you! <3

Patch:
diff --git a/faker/providers/currency/pt_BR/__init__.py b/faker/providers/currency/pt_BR/__init__.py
new file mode 100644
index 00000000..17ee8e3f
--- /dev/null
+++ b/faker/providers/currency/pt_BR/__init__.py
@@ -0,0 +1,9 @@
+from .. import Provider as CurrencyProvider
+
+
+class Provider(CurrencyProvider):
+
+    price_formats = ["#,##", "%#,##", "%##,##", "%.###,##", "%#.###,##"]
+
+    def pricetag(self):
+        return ("R$" + self.numerify(self.random_element(self.price_formats)))


Test patch:
diff --git a/tests/providers/test_currency.py b/tests/providers/test_currency.py
index 60703517..d63a8a38 100644
--- a/tests/providers/test_currency.py
+++ b/tests/providers/test_currency.py
@@ -346,3 +346,19 @@ class TestRoRo:
         for _ in range(num_samples):
             pricetag = faker.pricetag()
             assert isinstance(pricetag, str)
+
+
+class TestPtBr:
+    """Test pt_BR currency provider"""
+
+    num_samples = 100
+
+    @classmethod
+    def setup_class(cls):
+        from faker.providers.currency.pt_BR import Provider as PtBrCurrencyProvider
+        cls.provider = PtBrCurrencyProvider
+
+    def test_pricetag(self, faker, num_samples):
+        for _ in range(num_samples):
+            pricetag = faker.pricetag()
+            assert isinstance(pricetag, str)
Repository: joke2k/faker
Pull request #1518 (2021-09-23 16:32:03)

Task/jabertuhin/1517/add datetime provider for bd
### What does this changes

This pull-request addresses issue #1517 . I have created new `bn_BD` package under date_time package.

### What was wrong

N/A

### How this fixes it

N/A

Fixes #...

N/A

fcurella: Thank you!

Patch:
diff --git a/faker/providers/date_time/bn_BD/__init__.py b/faker/providers/date_time/bn_BD/__init__.py
new file mode 100644
index 00000000..888e4f1e
--- /dev/null
+++ b/faker/providers/date_time/bn_BD/__init__.py
@@ -0,0 +1,37 @@
+from .. import Provider as DateTimeProvider
+
+
+class Provider(DateTimeProvider):
+
+    DAY_NAMES = {
+        "0": "রবিবার",
+        "1": "সোমবার",
+        "2": "মঙ্গলবার",
+        "3": "বুধবার",
+        "4": "বৃহস্পতিবার",
+        "5": "শুক্রবার",
+        "6": "শনিবার",
+    }
+
+    MONTH_NAMES = {
+        "01": "জানুয়ারি",
+        "02": "ফেব্রুয়ারি",
+        "03": "মার্চ",
+        "04": "এপ্রিল",
+        "05": "মে",
+        "06": "জুন",
+        "07": "জুলাই",
+        "08": "আগস্ট",
+        "09": "সেপ্টেম্বর",
+        "10": "অক্টোবর",
+        "11": "নভেম্বর",
+        "12": "ডিসেম্বর",
+    }
+
+    def day_of_week(self):
+        day = self.date("%w")
+        return self.DAY_NAMES[day]
+
+    def month_name(self):
+        month = self.month()
+        return self.MONTH_NAMES[month]


Test patch:
diff --git a/tests/providers/test_date_time.py b/tests/providers/test_date_time.py
index 33c4f16a..62ee396c 100644
--- a/tests/providers/test_date_time.py
+++ b/tests/providers/test_date_time.py
@@ -18,6 +18,7 @@ from faker.providers.date_time import Provider as DatetimeProvider
 from faker.providers.date_time import change_year
 from faker.providers.date_time.ar_AA import Provider as ArProvider
 from faker.providers.date_time.ar_EG import Provider as EgProvider
+from faker.providers.date_time.bn_BD import Provider as BnBdProvider
 from faker.providers.date_time.cs_CZ import Provider as CsCzProvider
 from faker.providers.date_time.de_AT import Provider as DeAtProvider
 from faker.providers.date_time.de_DE import Provider as DeDeProvider
@@ -1147,3 +1148,18 @@ class TestRoRo(unittest.TestCase):
     def test_month(self):
         month = self.fake.month_name()
         assert month in RoRoProvider.MONTH_NAMES.values()
+
+
+class TestBnBd(unittest.TestCase):
+
+    def setUp(self):
+        self.fake = Faker('bn_BD')
+        Faker.seed(0)
+
+    def test_day(self):
+        day = self.fake.day_of_week()
+        assert day in BnBdProvider.DAY_NAMES.values()
+
+    def test_month(self):
+        month = self.fake.month_name()
+        assert month in BnBdProvider.MONTH_NAMES.values()
Repository: joke2k/faker
Pull request #1529 (2021-10-04 01:42:55)

Fix bug in pydecimal when returning max/min
When pydecimal returns the max or min values, it returns the exact
value provided by the user. The problem is that these arguments are
usually provided as float/int literals in tests, making the return
value not decimals sometimes.



### What does this changes

This patch makes sure we return a Decimal when returning the min or max.

### What was wrong

We were returning ints/floats if the user provided them as arguments.


wilbertom: Seems like a problem in CI and not my changes, ignoring.
fcurella: @joke2k can you remove appveyor? I don't think we need it anymore
fcurella: Thank you so much! <3

Patch:
diff --git a/faker/providers/python/__init__.py b/faker/providers/python/__init__.py
index 595e69fb..b056d186 100644
--- a/faker/providers/python/__init__.py
+++ b/faker/providers/python/__init__.py
@@ -198,9 +198,9 @@ class Provider(BaseProvider):
         # Because the random result might have the same number of decimals as max_value the random number
         # might be above max_value or below min_value
         if max_value is not None and result > max_value:
-            result = max_value
+            result = Decimal(max_value)
         if min_value is not None and result < min_value:
-            result = min_value
+            result = Decimal(min_value)
 
         return result
 


Test patch:
diff --git a/tests/providers/test_python.py b/tests/providers/test_python.py
index 6da60260..9742c9a0 100644
--- a/tests/providers/test_python.py
+++ b/tests/providers/test_python.py
@@ -256,6 +256,13 @@ class TestPydecimal(unittest.TestCase):
             result = self.fake.pydecimal(min_value=min_value)
             self.assertGreaterEqual(result, min_value)
 
+    def test_min_value_always_returns_a_decimal(self):
+        min_values = (0, 10, -1000, 1000, 999999)
+
+        for min_value in min_values:
+            result = self.fake.pydecimal(min_value=min_value)
+            self.assertIsInstance(result, decimal.Decimal)
+
     def test_min_value_and_left_digits(self):
         """
         Combining the min_value and left_digits keyword arguments produces
@@ -273,6 +280,13 @@ class TestPydecimal(unittest.TestCase):
             result = self.fake.pydecimal(max_value=max_value)
             self.assertLessEqual(result, max_value)
 
+    def test_max_value_always_returns_a_decimal(self):
+        max_values = (0, 10, -1000, 1000, 999999)
+
+        for max_value in max_values:
+            result = self.fake.pydecimal(max_value=max_value)
+            self.assertIsInstance(result, decimal.Decimal)
+
     def test_max_value_zero_and_left_digits(self):
         """
         Combining the max_value and left_digits keyword arguments produces
Repository: joke2k/faker
Pull request #1566 (2021-11-10 22:25:13)

Fix pydecimal with left_digits=0 not setting the left digit to 0
Fix `pydecimal` not setting the digit left of the decimal point to 0 when given `left_digits=0`.



Patch:
diff --git a/faker/providers/python/__init__.py b/faker/providers/python/__init__.py
index bee5084d..bf989fdb 100644
--- a/faker/providers/python/__init__.py
+++ b/faker/providers/python/__init__.py
@@ -193,14 +193,16 @@ class Provider(BaseProvider):
                 left_number = str(self.random_int(max(min_value or 0, 0), max_value))
             else:
                 min_left_digits = math.ceil(math.log10(max(min_value or 1, 1)))
-                left_digits = left_digits or self.random_int(min_left_digits, max_left_random_digits)
+                if left_digits is None:
+                    left_digits = self.random_int(min_left_digits, max_left_random_digits)
                 left_number = "".join([str(self.random_digit()) for i in range(0, left_digits)]) or "0"
         else:
             if min_value is not None:
                 left_number = str(self.random_int(max(max_value or 0, 0), abs(min_value)))
             else:
                 min_left_digits = math.ceil(math.log10(abs(min(max_value or 1, 1))))
-                left_digits = left_digits or self.random_int(min_left_digits, max_left_random_digits)
+                if left_digits is None:
+                    left_digits = self.random_int(min_left_digits, max_left_random_digits)
                 left_number = "".join([str(self.random_digit()) for i in range(0, left_digits)]) or "0"
 
         if right_digits is None:


Test patch:
diff --git a/tests/providers/test_python.py b/tests/providers/test_python.py
index 68f2b1d4..ac8b0b4d 100644
--- a/tests/providers/test_python.py
+++ b/tests/providers/test_python.py
@@ -235,6 +235,14 @@ class TestPydecimal(unittest.TestCase):
         left_digits = len(str(abs(int(result))))
         self.assertGreaterEqual(expected_left_digits, left_digits)
 
+    def test_left_digits_can_be_zero(self):
+        expected_left_digits = 0
+
+        result = self.fake.pydecimal(left_digits=expected_left_digits)
+
+        left_digits = int(result)
+        self.assertEqual(expected_left_digits, left_digits)
+
     def test_right_digits(self):
         expected_right_digits = 10
Repository: joke2k/faker
Pull request #1614 (2022-02-11 15:09:10)

Prevent "non-integer arguments to randrange()" warnings on Python 3.10
### What does this changes

From Python 3.10, non-integer arguments to `randrange()` produce a warning. This PR removes a path in which `pyfloat` can emit that warning.

### What was wrong

The existing implementation of `faker.providers.python.Provider.pyfloat` may pass float values to `random_int`, which in turn passes them directly to `randrange`.

### How this fixes it

`random_int` is already annotated to only accept integers, so I've made the fix in the `pyfloat` implementation (casting the arguments to `int` first).

An alternative would be to annotate `pyfloat` as only accepting integers, but this could be seen as a breaking change.

Related: https://github.com/joke2k/faker/issues/1538



Patch:
diff --git a/faker/providers/python/__init__.py b/faker/providers/python/__init__.py
index 301c8279..135012c1 100644
--- a/faker/providers/python/__init__.py
+++ b/faker/providers/python/__init__.py
@@ -155,7 +155,7 @@ class Provider(BaseProvider):
 
         return result
 
-    def _safe_random_int(self, min_value, max_value, positive):
+    def _safe_random_int(self, min_value: float, max_value: float, positive: bool) -> int:
         orig_min_value = min_value
         orig_max_value = max_value
 
@@ -169,7 +169,7 @@ class Provider(BaseProvider):
         if min_value == max_value:
             return self._safe_random_int(orig_min_value, orig_max_value, positive)
         else:
-            return self.random_int(min_value, max_value - 1)
+            return self.random_int(int(min_value), int(max_value - 1))
 
     def pyint(self, min_value: int = 0, max_value: int = 9999, step: int = 1) -> int:
         return self.generator.random_int(min_value, max_value, step=step)


Test patch:
diff --git a/tests/providers/test_python.py b/tests/providers/test_python.py
index f122dd28..819ea3fa 100644
--- a/tests/providers/test_python.py
+++ b/tests/providers/test_python.py
@@ -216,6 +216,18 @@ class TestPyfloat(unittest.TestCase):
         result = self.fake.pyfloat(positive=True, right_digits=0, max_value=1)
         self.assertGreater(result, 0)
 
+    @pytest.mark.skipif(sys.version_info < (3, 10), reason="Only relevant for Python 3.10 and later.")
+    @pytest.mark.filterwarnings(
+        # Convert the warning to an error for this test
+        r"error:non-integer arguments to randrange\(\):DeprecationWarning"
+    )
+    def test_float_min_and_max_value_does_not_warn(self):
+        """
+        Float arguments to randrange are deprecated from Python 3.10. This is a regression
+        test to check that `pyfloat` does not cause a deprecation warning.
+        """
+        self.fake.pyfloat(min_value=-1.0, max_value=1.0)
+
 
 class TestPydecimal(unittest.TestCase):
     def setUp(self):