Skip to content

Commit

Permalink
Merge branch 'master' into issue2085_pydecimal_wrong_distribution_for…
Browse files Browse the repository at this point in the history
…_min_max_values_of_dif_size
  • Loading branch information
fcurella authored Sep 4, 2024
2 parents c30f110 + 4240ef8 commit f1f7394
Show file tree
Hide file tree
Showing 20 changed files with 3,371 additions and 110 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 28.0.0
current_version = 28.4.1
files = VERSION faker/__init__.py docs/conf.py
commit = True
tag = True
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
## Changelog

### [v28.4.1 - 2024-09-04](https://github.com/joke2k/faker/compare/v28.4.0...v28.4.1)

* Fix issue where Faker does not properly convert min/max float values to `Decimal`. Thanks @bdjellabaldebaran.

### [v28.4.0 - 2024-09-04](https://github.com/joke2k/faker/compare/v28.3.0...v28.4.0)

* Add `it_IT` lorem provider. Thanks @gianni-di-noia.

### [v28.3.0 - 2024-09-04](https://github.com/joke2k/faker/compare/v28.2.0...v28.3.0)

* Fix male forms of female surnames in `uk_UA`.Thanks @AlexLitvino.

### [v28.2.0 - 2024-09-04](https://github.com/joke2k/faker/compare/v28.1.0...v28.2.0)

* Add `es_ES` isbn provider. Thanks @mondeja.

### [v28.1.0 - 2024-08-30](https://github.com/joke2k/faker/compare/v28.0.0...v28.1.0)

* Fix Incorrect City Spelling in `uk_UA` locale. Thanks @ch4zzy.

### [v28.0.0 - 2024-08-23](https://github.com/joke2k/faker/compare/v27.4.0...v28.0.0)

* Fix `pydecimal` handling of `positive` keyword. Thanks @tahzeer.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
28.0.0
28.4.1
2 changes: 1 addition & 1 deletion docs/coding_style.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ and/or origin of the data. If the source is a wiki, please also include the date
We only accept new data if it's coming from statistical sources, such as census or government institutions.
This includes names and their distribution.

You may include multiple sources, but each name must come from a source. We will not accept list of names compiled
You may include multiple sources, but each name must come from a source. We will not accept names authored
exclusively by contributors.


Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
# built documents.
#
# The short X.Y version.
version = "28.0.0"
version = "28.4.1"
# The full version, including alpha/beta/rc tags.
release = "28.0.0"
release = "28.4.1"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion faker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
from faker.generator import Generator
from faker.proxy import Faker

VERSION = "28.0.0"
VERSION = "28.4.1"

__all__ = ("Factory", "Generator", "Faker")
6 changes: 3 additions & 3 deletions faker/providers/automotive/uk_UA/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ class Provider(AutomotiveProvider):
"Kyiv_reg": (("AI", "KI", "TI", "ME"), "10"),
"Zhytomyr": (("AM", "KM", "TM", "MV"), "06"),
"Zakarpattia": (("AO", "KO", "MT", "MO"), "07"),
"Zaporizhia": (("AR", "KR", "TR", "MR"), "08"),
"Zaporizhzhia": (("AR", "KR", "TR", "MR"), "08"),
"IvanoFrankivsk": (("AT", "KT", "TO", "XS"), "09"),
"Kirovohrad": (("BA", "NA", "XA", "EA"), "12"),
"Luhansk": (("BB", "NV", "EE", "EV"), "13"),
"Lviv": (("BS", "NS", "SS", "ES"), "14"),
"Mykolaiv": (("BE", "NE", "XE", "XN"), "15"),
"Odessa": (("BN", "NN", "OO", "EN"), "16"),
"Odesa": (("BN", "NN", "OO", "EN"), "16"),
"Poltava": (("BI", "NI", "XI", "EI"), "17"),
"Rivne": (("BK", "NK", "XK", "EK"), "18"),
"Sumy": (("BM", "NM", "XM", "EM"), "19"),
"Ternopil": (("BO", "NO", "XO", "EO"), "20"),
"Kharkiv": (("AX", "KX", "XX", "EX"), "21"),
"Kherson": (("BT", "NT", "XT", "ET"), "22"),
"Khmelnytsky": (("BX", "NX", "OX", "RX"), "23"),
"Khmelnytskyi": (("BX", "NX", "OX", "RX"), "23"),
"Cherkasy": (("SA", "IA", "OA", "RA"), "24"),
"Chernihiv": (("SV", "IV", "OV", "RV"), "25"),
"Chernivtsi": (("SE", "IE", "OE", "RE"), "26"),
Expand Down
4 changes: 2 additions & 2 deletions faker/providers/date_time/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,7 @@ def _rand_seconds(self, start_datetime: int, end_datetime: int) -> float:
),
Country(
timezones=[
"Europe/Kiev",
"Europe/Kyiv",
"Europe/Uzhgorod",
"Europe/Zaporozhye",
"Europe/Simferopol",
Expand All @@ -1435,7 +1435,7 @@ def _rand_seconds(self, start_datetime: int, end_datetime: int) -> float:
alpha_3_code="UKR",
continent="Europe",
name="Ukraine",
capital="Kiev",
capital="Kyiv",
),
Country(
timezones=["Africa/Kampala"],
Expand Down
37 changes: 17 additions & 20 deletions faker/providers/isbn/__init__.py
Original file line number Diff line number Diff line change
@@ -1,63 +1,60 @@
from typing import List, Tuple

from faker.providers.isbn.rules import RegistrantRule
from typing import Dict, List, Tuple

from .. import BaseProvider
from .isbn import ISBN, ISBN10, ISBN13
from .rules import RULES
from .isbn import ISBN10, ISBN13, MAX_LENGTH

localized = True


class Provider(BaseProvider):
"""Generates fake ISBNs. ISBN rules vary across languages/regions
so this class makes no attempt at replicating all of the rules. It
only replicates the 978 EAN prefix for the English registration
groups, meaning the first 4 digits of the ISBN-13 will either be
978-0 or 978-1. Since we are only replicating 978 prefixes, every
ISBN-13 will have a direct mapping to an ISBN-10.
"""Generates fake ISBNs.
See https://www.isbn-international.org/content/what-isbn for the
format of ISBNs.
See https://www.isbn-international.org/range_file_generation for the
list of rules pertaining to each prefix/registration group.
"""

rules: Dict[str, Dict[str, List[Tuple[str, str, int]]]] = {}

def _body(self) -> List[str]:
"""Generate the information required to create an ISBN-10 or
ISBN-13.
"""
ean: str = self.random_element(RULES.keys())
reg_group: str = self.random_element(RULES[ean].keys())
ean: str = self.random_element(self.rules.keys())
reg_group: str = self.random_element(self.rules[ean].keys())

# Given the chosen ean/group, decide how long the
# registrant/publication string may be.
# We must allocate for the calculated check digit, so
# subtract 1
reg_pub_len: int = ISBN.MAX_LENGTH - len(ean) - len(reg_group) - 1
reg_pub_len: int = MAX_LENGTH - len(ean) - len(reg_group) - 1

# Generate a registrant/publication combination
reg_pub: str = self.numerify("#" * reg_pub_len)

# Use rules to separate the registrant from the publication
rules: List[RegistrantRule] = RULES[ean][reg_group]
rules = self.rules[ean][reg_group]
registrant, publication = self._registrant_publication(reg_pub, rules)
return [ean, reg_group, registrant, publication]

@staticmethod
def _registrant_publication(reg_pub: str, rules: List[RegistrantRule]) -> Tuple[str, str]:
def _registrant_publication(reg_pub: str, rules: List[Tuple[str, str, int]]) -> Tuple[str, str]:
"""Separate the registration from the publication in a given
string.
:param reg_pub: A string of digits representing a registration
and publication.
:param rules: A list of RegistrantRules which designate where
:param rules: A list of registrant rules which designate where
to separate the values in the string.
:returns: A (registrant, publication) tuple of strings.
"""
for rule in rules:
if rule.min <= reg_pub[:-1] <= rule.max:
reg_len = rule.registrant_length
if rule[0] <= reg_pub[:-1] <= rule[1]:
reg_len = rule[2]
break
else:
raise Exception("Registrant/Publication not found in registrant " "rule list.")
raise Exception(f"Registrant/Publication '{reg_pub}' not found in registrant rule list.")
registrant, publication = reg_pub[:reg_len], reg_pub[reg_len:]
return registrant, publication

Expand Down
32 changes: 31 additions & 1 deletion faker/providers/isbn/en_US/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,34 @@


class Provider(ISBNProvider):
pass
rules = {
# EAN prefix
"978": {
# Registration group
"0": [
# Registrant rule (min, max, registrant length)
("0000000", "1999999", 2),
("2000000", "2279999", 3),
("2280000", "2289999", 4),
("2290000", "6479999", 3),
("6480000", "6489999", 7),
("6490000", "6999999", 3),
("7000000", "8499999", 4),
("8500000", "8999999", 5),
("9000000", "9499999", 6),
("9500000", "9999999", 7),
],
"1": [
("0000000", "0999999", 2),
("1000000", "3999999", 3),
("4000000", "5499999", 4),
("5500000", "7319999", 5),
("7320000", "7399999", 7),
("7400000", "8697999", 5),
("8698000", "9729999", 6),
("9730000", "9877999", 4),
("9878000", "9989999", 6),
("9990000", "9999999", 7),
],
},
}
37 changes: 37 additions & 0 deletions faker/providers/isbn/es_ES/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from .. import Provider as ISBNProvider


class Provider(ISBNProvider):
rules = {
"978": {
"84": [
("0000000", "0999999", 2),
("1000000", "1049999", 5),
("1050000", "1199999", 4),
("1200000", "1299999", 6),
("1300000", "1399999", 4),
("1400000", "1499999", 3),
("1500000", "1999999", 5),
("2000000", "6999999", 3),
("7000000", "8499999", 4),
("8500000", "8999999", 5),
("9000000", "9199999", 4),
("9200000", "9239999", 6),
("9240000", "9299999", 5),
("9300000", "9499999", 6),
("9500000", "9699999", 5),
("9700000", "9999999", 4),
],
"13": [
("0000000", "0099999", 2),
("0100000", "5999999", 0),
("6000000", "6049999", 3),
("6050000", "6999999", 0),
("7000000", "7349999", 4),
("7350000", "8749999", 0),
("8750000", "8999999", 5),
("9000000", "9899999", 0),
("9900000", "9999999", 6),
],
},
}
4 changes: 2 additions & 2 deletions faker/providers/isbn/isbn.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

from typing import Any, Optional

MAX_LENGTH = 13

class ISBN:
MAX_LENGTH = 13

class ISBN:
def __init__(
self,
ean: Optional[str] = None,
Expand Down
45 changes: 0 additions & 45 deletions faker/providers/isbn/rules.py

This file was deleted.

Loading

0 comments on commit f1f7394

Please sign in to comment.