-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d9fc37a
Showing
175 changed files
with
17,038 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Sphinx build info version 1 | ||
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. | ||
config: 250e992d197686300086a0ca27a1f167 | ||
tags: 645f666f9bcd5a90fca523b33c5a78b7 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
--- | ||
jupytext: | ||
formats: md:myst | ||
text_representation: | ||
extension: .md | ||
format_name: myst | ||
format_version: 0.13 | ||
jupytext_version: 1.11.5 | ||
kernelspec: | ||
display_name: Python 3 | ||
language: python | ||
name: python3 | ||
--- | ||
# Casts and other utils | ||
|
||
|
||
Casting is essential in programming. With Pydicts I try to put together main castings, to work easyly with all kind of data structures. | ||
|
||
## ignore_exception | ||
|
||
Morever, this module casting function has two additional parameters, that are useful for rapid development: | ||
|
||
- **ignore_exception**. By default False. If you set this parameter to True, casting with return ignore_exception_value if a CastException happens. | ||
- **ignore_exception_value**. By default None. It's the value casting will return if a CastException happens | ||
|
||
For example, this code `casts.str2bool(None)` will raise a CastException, due to None is not a valid value. | ||
|
||
But this code will return None | ||
```{code-cell} | ||
from pydicts import casts | ||
casts.str2bool(None, ignore_exception=True) | ||
``` | ||
|
||
And this code will return False | ||
```{code-cell} | ||
from pydicts import casts | ||
casts.str2bool(None, ignore_exception=True,ignore_exception_value=False) | ||
``` | ||
|
||
## Casts | ||
|
||
### base64bytes2bytes | ||
|
||
### bytes2base64bytes | ||
|
||
### bytes2str | ||
|
||
### dtaware2dtnaive | ||
|
||
### dtaware2epochmicros | ||
|
||
### dtaware2epochms | ||
|
||
### dtaware2str | ||
|
||
### dtnaive2dtaware | ||
|
||
### dtnaive2str | ||
|
||
### epochmicros2dtaware | ||
|
||
### epochms2dtaware | ||
|
||
### none2alternative | ||
|
||
### str2bool | ||
|
||
Converts a string to a boolean | ||
|
||
```{code-cell} | ||
from pydicts import casts | ||
casts.str2bool("true") | ||
``` | ||
```{code-cell} | ||
from pydicts import casts | ||
casts.str2bool("0") | ||
``` | ||
|
||
These calls will raise CastException: | ||
- `casts.str2bool(None)` | ||
- `casts.str2bool(True)` | ||
- `casts.str2bool("Verdadero")` | ||
|
||
|
||
### str2bytes | ||
|
||
### str2date | ||
|
||
### str2decimal | ||
|
||
### str2dtaware | ||
|
||
### str2dtnaive | ||
|
||
### str2time | ||
|
||
### str2timedelta | ||
|
||
### time2str | ||
|
||
### timedelta2str | ||
|
||
## Date and time utils | ||
|
||
### date_first_of_the_month | ||
|
||
### date_first_of_the_next_x_months | ||
|
||
### date_first_of_the_year | ||
|
||
### date_last_of_the_month | ||
|
||
### date_last_of_the_next_x_months | ||
|
||
### date_last_of_the_year | ||
|
||
### dtaware | ||
|
||
### dtaware_changes_tz | ||
|
||
### dtaware_day_end | ||
|
||
### dtaware_day_end_from_date | ||
|
||
### dtaware_day_start | ||
|
||
### dtaware_day_start_from_date | ||
|
||
### dtaware_month_end | ||
|
||
### dtaware_month_start | ||
|
||
### dtaware_now | ||
|
||
Returns a aware datetime object of current moment. By default returns UTC timezone | ||
|
||
```{code-cell} | ||
from pydicts import casts | ||
print(casts.dtaware_now()) | ||
print(casts.dtaware_now("Europe/Madrid")) | ||
``` | ||
|
||
|
||
### dtaware_year_end | ||
|
||
### dtaware_year_start | ||
|
||
### dtnaive | ||
|
||
|
||
### dtnaive_day_end | ||
|
||
### dtnaive_day_end_from_date | ||
|
||
### dtnaive_day_start | ||
|
||
### dtnaive_day_start_from_date | ||
|
||
### dtnaive_now | ||
|
||
Returns a naive datetime object of current moment. By default returns UTC timezone | ||
|
||
```{code-cell} | ||
from pydicts import casts | ||
casts.dtnaive_now() | ||
``` | ||
|
||
### is_aware | ||
|
||
Returns if a datetime object is aware (with timezone) | ||
|
||
```{code-cell} | ||
from pydicts import casts | ||
print(casts.is_aware(casts.dtaware_now())) | ||
print(casts.is_aware(casts.dtnaive_now())) | ||
``` | ||
|
||
### is_naive | ||
|
||
Returns if a datetime object is naive (without timezone) | ||
|
||
```{code-cell} | ||
from pydicts import casts | ||
print(casts.is_naive(casts.dtaware_now())) | ||
print(casts.is_naive(casts.dtnaive_now())) | ||
``` | ||
|
||
### months | ||
|
||
|
||
## Other utils | ||
|
||
### is_noe | ||
|
||
Return if value is None or an empty string | ||
|
||
```{code-cell} | ||
from pydicts import casts | ||
print(casts.is_noe(None)) | ||
print(casts.is_noe("")) | ||
print(casts.is_noe(1)) | ||
``` | ||
|
||
|
||
### object_or_empty | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
jupytext: | ||
formats: md:myst | ||
text_representation: | ||
extension: .md | ||
format_name: myst | ||
format_version: 0.13 | ||
jupytext_version: 1.11.5 | ||
kernelspec: | ||
display_name: Python 3 | ||
language: python | ||
name: python3 | ||
--- | ||
# Currency |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Pydicts project | ||
|
||
:::{note} | ||
In construction. Please help me | ||
::: | ||
|
||
## Casts | ||
|
||
Casting is essential in programming. With Pydicts I try to put together main castings, to work easyly with all kind of data structures. | ||
|
||
## Data structures | ||
|
||
PyDicts uses several acronyms to call modulues, functions and parameters | ||
|
||
- **LOD**: List of dictionaries `[{"a":1,"b":2}, {"a":3,"b":4}]` | ||
- **LOOD**: List of ordered dictionaries (OrderedDicts from collections module) `[OrderedDict([('a', 1), ('b', 2)]), OrderedDict([('a', 3), ('b', 4)])]` | ||
- **LOL**: List of lists `[[1, 2, 3], [4, 5, 6]]` | ||
- **DOD**: Dictionary of dictionaries `{'key2': {'a': 1, 'b': 2}, 'key1': {'a': 1, 'b': 2}}` | ||
- **ODOD**: Ordered dictionary of dictionaries `OrderedDict({'key2': {'a': 1, 'b': 2}, 'key1': {'a': 1, 'b': 2}})` | ||
- **LOD_XYV**: List of dictionaries with x-y-value keys `[{'X': 21, 'Y': 12, 'value': 180}, {'X': 2, 'Y': 122, 'value': 170}]` | ||
- **LOD_YMV**: List of dictionaries with year-month-value keys `[{'year': 2021, 'month': 1, 'value': 12.12}, {'year': 2023, 'month': 3, 'value': 13.03}]` | ||
|
Oops, something went wrong.