pydiverse-common 0.3.2__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pydiverse/common/__init__.py +55 -0
- pydiverse/common/dtypes.py +418 -0
- pydiverse/common/errors/__init__.py +9 -0
- pydiverse/common/util/__init__.py +13 -0
- pydiverse/common/util/computation_tracing.py +341 -0
- pydiverse/common/util/deep_map.py +100 -0
- pydiverse/common/util/deep_merge.py +55 -0
- pydiverse/common/util/disposable.py +28 -0
- pydiverse/common/util/hashing.py +32 -0
- pydiverse/common/util/import_.py +135 -0
- pydiverse/common/util/structlog.py +115 -0
- pydiverse/common/version.py +10 -0
- pydiverse_common-0.3.2.dist-info/METADATA +64 -0
- pydiverse_common-0.3.2.dist-info/RECORD +16 -0
- pydiverse_common-0.3.2.dist-info/WHEEL +5 -0
- pydiverse_common-0.3.2.dist-info/licenses/LICENSE +29 -0
@@ -0,0 +1,115 @@
|
|
1
|
+
# Copyright (c) QuantCo and pydiverse contributors 2025-2025
|
2
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
3
|
+
import logging
|
4
|
+
import sys
|
5
|
+
import textwrap
|
6
|
+
import types
|
7
|
+
from io import StringIO
|
8
|
+
|
9
|
+
try:
|
10
|
+
import structlog
|
11
|
+
from structlog.typing import EventDict, WrappedLogger
|
12
|
+
|
13
|
+
structlog_installed = True
|
14
|
+
except ImportError:
|
15
|
+
structlog = types.ModuleType("structlog")
|
16
|
+
|
17
|
+
class dev:
|
18
|
+
class ConsoleRenderer:
|
19
|
+
pass
|
20
|
+
|
21
|
+
structlog.dev = dev
|
22
|
+
structlog_installed = False
|
23
|
+
EventDict, WrappedLogger = None, None
|
24
|
+
|
25
|
+
|
26
|
+
class StructlogHandler(logging.Handler):
|
27
|
+
"""
|
28
|
+
Stdlib logging handler that feeds all events back into structlog
|
29
|
+
|
30
|
+
Can't be used with a structlog logger_factory that uses the logging library,
|
31
|
+
otherwise logging would result in an infinite loop.
|
32
|
+
"""
|
33
|
+
|
34
|
+
def __init__(self, *args, **kw):
|
35
|
+
super().__init__(*args, **kw)
|
36
|
+
self._log = structlog.get_logger()
|
37
|
+
|
38
|
+
def emit(self, record):
|
39
|
+
msg = self.format(record)
|
40
|
+
self._log.log(record.levelno, msg, logger=record.name)
|
41
|
+
|
42
|
+
|
43
|
+
class PydiverseConsoleRenderer(structlog.dev.ConsoleRenderer):
|
44
|
+
"""
|
45
|
+
Custom subclass of the structlog ConsoleRenderer that allows rendering
|
46
|
+
specific values in the event dict on separate lines.
|
47
|
+
"""
|
48
|
+
|
49
|
+
def __init__(self, *args, **kwargs):
|
50
|
+
self._render_keys = kwargs.pop("render_keys", [])
|
51
|
+
super().__init__(*args, **kwargs)
|
52
|
+
|
53
|
+
def __call__(self, logger: WrappedLogger, name: str, event_dict: EventDict):
|
54
|
+
render_objects = {}
|
55
|
+
for key in self._render_keys:
|
56
|
+
obj = event_dict.pop(key, None)
|
57
|
+
if obj is not None:
|
58
|
+
render_objects[key] = obj
|
59
|
+
|
60
|
+
result = super().__call__(logger, name, event_dict)
|
61
|
+
sio = StringIO()
|
62
|
+
sio.write(result)
|
63
|
+
|
64
|
+
for key, obj in render_objects.items():
|
65
|
+
string_rep = str(obj)
|
66
|
+
sio.write(
|
67
|
+
"\n"
|
68
|
+
+ " ["
|
69
|
+
+ self._styles.kv_key
|
70
|
+
+ key
|
71
|
+
+ self._styles.reset
|
72
|
+
+ "]"
|
73
|
+
+ "\n"
|
74
|
+
+ textwrap.indent(string_rep, prefix=" " + self._styles.kv_value)
|
75
|
+
+ self._styles.reset
|
76
|
+
)
|
77
|
+
|
78
|
+
return sio.getvalue()
|
79
|
+
|
80
|
+
|
81
|
+
def setup_logging(
|
82
|
+
log_level=logging.INFO,
|
83
|
+
log_stream=sys.stderr,
|
84
|
+
timestamp_format="%Y-%m-%d %H:%M:%S.%f",
|
85
|
+
):
|
86
|
+
"""Configures structlog and logging with sane defaults."""
|
87
|
+
|
88
|
+
if structlog_installed:
|
89
|
+
# Redirect all logs submitted to logging to structlog
|
90
|
+
logging.basicConfig(
|
91
|
+
format="%(message)s",
|
92
|
+
level=log_level,
|
93
|
+
handlers=[StructlogHandler()],
|
94
|
+
)
|
95
|
+
# Configure structlog
|
96
|
+
structlog.configure(
|
97
|
+
processors=[
|
98
|
+
structlog.contextvars.merge_contextvars,
|
99
|
+
structlog.processors.StackInfoRenderer(),
|
100
|
+
structlog.dev.set_exc_info,
|
101
|
+
structlog.processors.add_log_level,
|
102
|
+
structlog.processors.TimeStamper(timestamp_format),
|
103
|
+
PydiverseConsoleRenderer(
|
104
|
+
render_keys=["query", "table_obj", "task", "table", "detail"]
|
105
|
+
),
|
106
|
+
],
|
107
|
+
wrapper_class=structlog.make_filtering_bound_logger(log_level),
|
108
|
+
logger_factory=structlog.PrintLoggerFactory(log_stream),
|
109
|
+
cache_logger_on_first_use=True,
|
110
|
+
)
|
111
|
+
else:
|
112
|
+
logging.basicConfig(
|
113
|
+
format="%(message)s",
|
114
|
+
level=log_level,
|
115
|
+
)
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Copyright (c) QuantCo and pydiverse contributors 2025-2025
|
2
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
3
|
+
|
4
|
+
from importlib.metadata import PackageNotFoundError, version
|
5
|
+
|
6
|
+
try:
|
7
|
+
__version__ = version(__package__ or __name__)
|
8
|
+
except PackageNotFoundError:
|
9
|
+
# Running from a Git checkout or an editable install
|
10
|
+
__version__ = "0.0.0+dev"
|
@@ -0,0 +1,64 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: pydiverse-common
|
3
|
+
Version: 0.3.2
|
4
|
+
Summary: Common functionality shared between pydiverse libraries
|
5
|
+
Author: QuantCo, Inc.
|
6
|
+
Author-email: Martin Trautmann <windiana@users.sf.net>, Finn Rudolph <finn.rudolph@t-online.de>
|
7
|
+
License: BSD 3-Clause License
|
8
|
+
|
9
|
+
Copyright (c) 2022, pydiverse
|
10
|
+
All rights reserved.
|
11
|
+
|
12
|
+
Redistribution and use in source and binary forms, with or without
|
13
|
+
modification, are permitted provided that the following conditions are met:
|
14
|
+
|
15
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
16
|
+
list of conditions and the following disclaimer.
|
17
|
+
|
18
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
19
|
+
this list of conditions and the following disclaimer in the documentation
|
20
|
+
and/or other materials provided with the distribution.
|
21
|
+
|
22
|
+
3. Neither the name of the copyright holder nor the names of its
|
23
|
+
contributors may be used to endorse or promote products derived from
|
24
|
+
this software without specific prior written permission.
|
25
|
+
|
26
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
27
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
28
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
29
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
30
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
31
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
32
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
33
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
34
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
35
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
36
|
+
License-File: LICENSE
|
37
|
+
Classifier: Development Status :: 4 - Beta
|
38
|
+
Classifier: Intended Audience :: Developers
|
39
|
+
Classifier: Intended Audience :: Science/Research
|
40
|
+
Classifier: License :: OSI Approved :: BSD License
|
41
|
+
Classifier: Programming Language :: Python :: 3
|
42
|
+
Classifier: Programming Language :: Python :: 3.10
|
43
|
+
Classifier: Programming Language :: Python :: 3.11
|
44
|
+
Classifier: Programming Language :: Python :: 3.12
|
45
|
+
Classifier: Programming Language :: Python :: 3.13
|
46
|
+
Classifier: Programming Language :: SQL
|
47
|
+
Classifier: Topic :: Database
|
48
|
+
Classifier: Topic :: Scientific/Engineering
|
49
|
+
Classifier: Topic :: Software Development
|
50
|
+
Description-Content-Type: text/markdown
|
51
|
+
|
52
|
+
# pydiverse.common
|
53
|
+
|
54
|
+
[](https://github.com/pydiverse/pydiverse.common/actions/workflows/tests.yml)
|
55
|
+
|
56
|
+
A base package for different libraries in the pydiverse library collection.
|
57
|
+
This includes functionality like a type-system for tabular data (SQL and DataFrame).
|
58
|
+
This type-system is used for ensuring reliable operation of the pydiverse library
|
59
|
+
with various execution backends like Pandas, Polars, and various SQL dialects.
|
60
|
+
|
61
|
+
## Usage
|
62
|
+
|
63
|
+
pydiverse.common can either be installed via pypi with `pip install pydiverse-common` or via
|
64
|
+
conda-forge with `conda install pydiverse-common -c conda-forge`.
|
@@ -0,0 +1,16 @@
|
|
1
|
+
pydiverse/common/__init__.py,sha256=eK3Wji6868cvXeq6e9YPRxi20vU6i9Lql4IzG6iB4B4,784
|
2
|
+
pydiverse/common/dtypes.py,sha256=OtxOLnA5HIX9OandrrSgKS8bzERnntLRvQF-hSzvlbU,12509
|
3
|
+
pydiverse/common/version.py,sha256=1IU_m4r76_Qq0u-Tyo2_bERZFOkh0ZFueVzDqcCfLO0,336
|
4
|
+
pydiverse/common/errors/__init__.py,sha256=FNeEfVbUa23b9sHkFsmxHYhY6sRgjaZysPQmlovpJrI,262
|
5
|
+
pydiverse/common/util/__init__.py,sha256=fGdKZtLaTVBW7NfCpX7rZhKHwUzmBnsuY2akDOnAnjc,315
|
6
|
+
pydiverse/common/util/computation_tracing.py,sha256=HeXRHRUI8vxpzQ27Xcpa0StndSTP63EMT9vj4trPJUY,9697
|
7
|
+
pydiverse/common/util/deep_map.py,sha256=JtY5ViWMMelOiLzPF7ZjzruCfB-bETISGxCk37qETxg,2540
|
8
|
+
pydiverse/common/util/deep_merge.py,sha256=bV5p5_lsC-9nFah28EiEyG2h6U3Z5AuTqSooxOgCHN0,1929
|
9
|
+
pydiverse/common/util/disposable.py,sha256=4XoGz70YRWA9TAqnUBvRCTAdsOGBviFN0gzxU7veY9o,993
|
10
|
+
pydiverse/common/util/hashing.py,sha256=6x77BKg-w61u59fuTe9di0BtU-kEKH6UTRcKsRoYJ84,1196
|
11
|
+
pydiverse/common/util/import_.py,sha256=K7dSgz4YyrqEvqhoOzbwgD7D8HScMoO5XoSWtjbaoUs,4056
|
12
|
+
pydiverse/common/util/structlog.py,sha256=g0d8yaXBzAxmGNGZYMnMP9dsSQ__jN44GAY8Mb0ABeI,3487
|
13
|
+
pydiverse_common-0.3.2.dist-info/METADATA,sha256=fwld0ZxdHloPOoeRj-X9WLZPwrNpQ4QuYeD1BZJ7qPo,3333
|
14
|
+
pydiverse_common-0.3.2.dist-info/WHEEL,sha256=tkmg4JIqwd9H8mL30xA7crRmoStyCtGp0VWshokd1Jc,105
|
15
|
+
pydiverse_common-0.3.2.dist-info/licenses/LICENSE,sha256=AcE6SDVuAq6v9ZLE_8eOCe_NvSE0rAPR3NR7lSowYh4,1517
|
16
|
+
pydiverse_common-0.3.2.dist-info/RECORD,,
|
@@ -0,0 +1,29 @@
|
|
1
|
+
BSD 3-Clause License
|
2
|
+
|
3
|
+
Copyright (c) 2022, pydiverse
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
8
|
+
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
10
|
+
list of conditions and the following disclaimer.
|
11
|
+
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
14
|
+
and/or other materials provided with the distribution.
|
15
|
+
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
17
|
+
contributors may be used to endorse or promote products derived from
|
18
|
+
this software without specific prior written permission.
|
19
|
+
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|