Git Product home page Git Product logo

bcg-x-official / pytools Goto Github PK

View Code? Open in Web Editor NEW
33.0 7.0 3.0 12.22 MB

Foundational tools for BCG X's data science packages.

Home Page: https://bcg-x-official.github.io/pytools/

License: Apache License 2.0

Python 99.39% Shell 0.02% CSS 0.26% JavaScript 0.34%
python documentation runtime-validation data-simulation api-development parallelization visualization expression-tree representation runtime-typechecking

pytools's Introduction

sphinx/source/_images/gamma_pytools_logo.png


pytools is an open source library containing general machine learning and visualisation utilities for reuse, including:

  • Basic tools for API development, supporting documentation, deprecation, and run-time validation
  • Support for simulating classification and regression data
  • Utilities for constructing complex expressions and rendering them as indented strings
  • Support for fitting objects to data, and testing whether an object is fitted
  • Parallelization based on the joblib package
  • A lean MVC framework for rendering basic visualizations in different styles, e.g., as matplotlib charts or as plain text

pypi conda azure_build azure_code_cov python_versions code_style made_with_sphinx_doc license_badge

Installation

pytools supports both PyPI and Anaconda. We recommend to install pytools into a dedicated environment.

Anaconda

conda create -n pytools
conda activate pytools
conda install -c bcg_gamma -c conda-forge gamma-pytools

Pip

macOS and Linux:

python -m venv pytools
source pytools/bin/activate
pip install gamma-pytools

Windows:

python -m venv pytools
pytools\Scripts\activate.bat
pip install gamma-pytools

Documentation

For the pytools API reference see the documentation.

Changes and additions to new versions are summarized in the release notes.

Contributing

pytools is stable and is being supported long-term.

Contributions to pytools are welcome and appreciated. For any bug reports or feature requests/enhancements please use the appropriate GitHub form, and if you wish to do so, please open a PR addressing the issue.

We do ask that for any major changes please discuss these with us first via an issue or at our team email: [email protected].

For further information on contributing please see our contribution guide.

License

pytools is licensed under Apache 2.0 as described in the LICENSE file.

BCG GAMMA

We are always on the lookout for passionate and talented data scientists to join the BCG GAMMA team. If you would like to know more you can find out about BCG GAMMA here, or have a look at career opportunities.

pytools's People

Contributors

breakbotz avatar j-ittner avatar jason-bentley avatar jckkvs avatar joerg-schneider avatar konst-int-i avatar mgelsm avatar mtsokol avatar sithankanna avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

pytools's Issues

BUG: Encountering error when using a function with `None` return type

Describe the bug
An error in gamma-pytools prevents users from seeing an informative error message, when they use -> None to denote the return type of a typed function with more than zero arguments in an fluxus/ARTKIT flow.

To Reproduce
To reproduce the error you can use this minimal example:
pip install artkit==1.0.2

import artkit.api as ak

def say_hello(file_path: str) -> None:
    print(f"Hello {file_path}!")

pipeline = ak.chain(
        ak.step("hi", say_hello),
)

ak.run(pipeline, input={"file_path": "world!"}).to_frame()

Expected behavior
Users encounter the following error when using a function with only side effects: TypeError: Function say_hello() of step 'hi' must return a dictionary, an iterable of dictionaries, or an async iterable of dictionaries, not <class 'NoneType'>

Desktop:

  • Python: 3.11.9
  • OS: MacOS

Additional context
Full stack trace:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[152], line 7
      3 def say_hello(file_path: str) -> None:
      4     print(f"Hello {file_path}!")
      6 pipeline = ak.chain(
----> 7         ak.step("hi", say_hello),
      8 )
     10 ak.run(pipeline, input={"file_path": "world!"}).to_frame()

File ~/.pyenv/versions/3.11.9/envs/rai_red_ft/lib/python3.11/site-packages/fluxus/functional/_functions.py:242, in step(_name, _function_or_data, **kwargs)
    234     return DictProducer(
    235         lambda: aiter(cast(AsyncIterable[Mapping[str, Any]], _function_or_data)),
    236         name=_name,
    237     )
    238 elif (
    239     not isinstance(_function_or_data, FunctionType)
    240     or _function_or_data.__code__.co_varnames
    241 ):
--> 242     return Step(_name, _function_or_data, **kwargs)
    243 else:
    244     return DictProducer(_function_or_data, name=_name)

File ~/.pyenv/versions/3.11.9/envs/rai_red_ft/lib/python3.11/site-packages/fluxus/functional/conduit/_step.py:178, in Step.__init__(self, _name, _function, **kwargs)
    172 if invalid_kwargs:
    173     raise ValueError(
    174         "Names of keyword arguments must be valid identifiers, but got: "
    175         + ", ".join(map(repr, invalid_kwargs))
    176     )
--> 178 function_arguments = _validate_function(
    179     step=_name, function=_function, kwargs=kwargs
    180 )
    181 self._name = _name
    182 self._function = _function

File ~/.pyenv/versions/3.11.9/envs/rai_red_ft/lib/python3.11/site-packages/fluxus/functional/conduit/_step.py:418, in _validate_function(step, function, kwargs)
    411         if return_annotation is None:  # pragma: no cover
    412             # This should never happen
    413             raise TypeError(
    414                 f"Return type of function {function.__name__} of step {step!r} "
    415                 f"is a forward reference that cannot be resolved: "
    416                 f"{return_annotation!r}"
    417             )
--> 418     if not any(
    419         issubclass_generic(return_annotation, tp)
    420         for tp in (
    421             Mapping[str, Any],
    422             Iterable[Mapping[str, Any]],
    423             AsyncIterable[Mapping[str, Any]],
    424             Awaitable[Mapping[str, Any]],
    425         )
    426     ):
    427         raise TypeError(
    428             f"Return type of function {function.__name__} of step {step!r} must be "
    429             "one of Mapping[str, Any], Iterable[Mapping[str, Any]], or "
    430             f"AsyncIterable[Mapping[str, Any]], but got: {return_annotation}"
    431         )
    433 return function_arguments

File ~/.pyenv/versions/3.11.9/envs/rai_red_ft/lib/python3.11/site-packages/fluxus/functional/conduit/_step.py:419, in <genexpr>(.0)
    411         if return_annotation is None:  # pragma: no cover
    412             # This should never happen
    413             raise TypeError(
    414                 f"Return type of function {function.__name__} of step {step!r} "
    415                 f"is a forward reference that cannot be resolved: "
    416                 f"{return_annotation!r}"
    417             )
    418     if not any(
--> 419         issubclass_generic(return_annotation, tp)
    420         for tp in (
    421             Mapping[str, Any],
    422             Iterable[Mapping[str, Any]],
    423             AsyncIterable[Mapping[str, Any]],
    424             Awaitable[Mapping[str, Any]],
    425         )
    426     ):
    427         raise TypeError(
    428             f"Return type of function {function.__name__} of step {step!r} must be "
    429             "one of Mapping[str, Any], Iterable[Mapping[str, Any]], or "
    430             f"AsyncIterable[Mapping[str, Any]], but got: {return_annotation}"
    431         )
    433 return function_arguments

File ~/.pyenv/versions/3.11.9/envs/rai_red_ft/lib/python3.11/site-packages/pytools/typing/_typing.py:399, in issubclass_generic(subclass, base)
    396 elif base is Never:
    397     return False
--> 399 subclass = _replace_deprecated_type(subclass)
    400 base = _replace_deprecated_type(base)
    402 # Get the non-generic origin of the base class

File ~/.pyenv/versions/3.11.9/envs/rai_red_ft/lib/python3.11/site-packages/pytools/typing/_typing.py:580, in _replace_deprecated_type(tp)
    570 def _replace_deprecated_type(tp: type) -> type:
    571     """
    572     Replace deprecated types in :mod:`typing` with their canonical replacements in
    573     :mod:`collections.abc`.
   (...)
    577         deprecated
    578     """
--> 580     if tp.__module__ == "typing":
    581         # Check if the same type is defined in collections.abc
    582         origin: type | None = get_origin(tp)
    583         if origin is not None and origin.__module__ == "collections.abc":

AttributeError: 'NoneType' object has no attribute '__module__'

inherited-members doesn't support instance attributes on super class

Describe the bug
The inherited-members doesn't support instance attributes on super class when generating sphinx documentation.
Fix appears to be on the way see here: sphinx-doc/sphinx#8587 so an update to Sphinx 3.5 once stable should hopefully resolve the issue.

To Reproduce
Create documentation using python make.py html and view DEFAULT_STYLE in the attribute summary for pytools.vz.Drawer vs pytools.viz.dendrogram and see that only one is described.

Expected behavior
In all places where DEFAULT_STYLE is shown in an attribute summary the description should be present.

Screenshots
image
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.