Giter VIP home page Giter VIP logo

pinttrs's Introduction

Pinttrs

Pint meets attrs

PyPI version Conda version

GitHub Workflow Status (branch) Documentation Status

Rye Ruff Code style: black

Motivation

The amazing attrs library is a game-changer when it comes to writing classes. Its initialization sequence notably allows for automated conversion and verification of attribute values. This package is an attempt at designing a system to apply units automatically and reliably to attributes with Pint.

Features

  • Attach automatically units to unitless values passed to initialize an attribute
  • Verify unit compatibility when assigning a value to an attribute
  • Interpret units in dictionaries with a simple syntax
  • Define unit context to vary unitless value interpretation dynamically

Check the documentation for more detail.

License

Pinttrs is distributed under the terms of the MIT license.

About

Pinttrs is written and maintained by Vincent Leroy.

Development is supported by Rayference.

Pinttrs is a component of the Eradiate radiative transfer model.

The Pinttrs logo is based on Agus Nugroho's glass icon and parts of the attrs logo.

pinttrs's People

Contributors

leroyvn avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pinttrs's Issues

units_compatible does not take pint.Unit as arguments type

The signature of units_compatible() says that its arguments must be of type pint.Unit, however the following code:

import pint
from pinttr.util import units_compatible

units_compatible(pint.Unit("m"), pint.Unit("km"))

raises

AttributeError: 'Unit' object has no attribute '_get_non_multiplicative_units'

whereas:

ureg = pint.UnitRegistry()
units_compatible(ureg("m"), ureg("km"))

works fine, which suggests that the arguments type of units_compatible() is pint.Quantity, instead of pint.Unit?

Inventory objects are not exported properly

Using sphobjinv, it turns out that Pinttrs docs do not export any symbols:

$ sphobjinv convert plain objects.inv
$ cat objects.txt
# Sphinx inventory version 2
# Project: Pinttrs
# Version: 21.3
# The remainder of this file is compressed using zlib.
api std:label -1 rst/api.html#$ API Reference
api-converters std:label -1 rst/api.html#$ Converters [pinttr.converters]
api-dict_interpretation std:label -1 rst/api.html#api-dict-interpretation Dictionary interpretation
api-dynamic std:label -1 rst/api.html#$ Dynamic unit management
api-exceptions std:label -1 rst/api.html#$ Exceptions [pinttr.exceptions]
api-main std:label -1 rst/api.html#$ Main interface
api-unit_registry std:label -1 rst/api.html#api-unit-registry Default unit registry
api-utilities std:label -1 rst/api.html#$ Utilities [pinttr.util]
api-validators std:label -1 rst/api.html#$ Validators [pinttr.validators]
compatible std:label -1 rst/compatible.html#$ What are “compatible units”?
dev std:label -1 rst/dev.html#$ Developer guide
genindex std:label -1 genindex.html Index
index std:doc -1 index.html Pinttrs
modindex std:label -1 py-modindex.html Module Index
py-modindex std:label -1 py-modindex.html Python Module Index
rst/api std:doc -1 rst/api.html API Reference
rst/changes std:doc -1 rst/changes.html Changelog
rst/compatible std:doc -1 rst/compatible.html What are “compatible units”?
rst/dev std:doc -1 rst/dev.html Developer guide
rst/usage std:doc -1 rst/usage.html Usage
search std:label -1 search.html Search Page
usage std:label -1 rst/usage.html#$ Usage
usage-attach_units std:label -1 rst/usage.html#usage-attach-units Attaching units to attributes
usage-attach_units-validators_converters std:label -1 rst/usage.html#usage-attach-units-validators-converters Validators and converters
usage-interpret_dicts std:label -1 rst/usage.html#usage-interpret-dicts Interpreting units in dicts
usage-unit_contexts std:label -1 rst/usage.html#usage-unit-contexts Unit contexts

This doesn't allow for linking from external projects.


After a quick investigation, it turns out that fresher iterations of the package generate correct inventory files. Check again after the next release.

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.