Comments (5)
First, sorry for breaking things. The move to the new Formatter delegate allows more flexibility so I think this annoyance will pay off. Let me answer each of your questions:
Wouldn't a Unit object always be related to a registry, even if it's the default one ?
The formatter also format unit like objects (i.e. dicts mapping names to exponents) which do not necesesary require a registry.
Also, the way register_unit_format is written, wouldn't registry always be None
Yes. I was planning to try a solution but there was no need until now.
The idea would be to make this function look and instantiate the registered formatters.
def get_formatter(self, spec: str):
if spec == "":
return self._formatters["D"]
for k, v in self._formatters.items():
if k in spec:
return v
try:
orphan_fmt = REGISTERED_FORMATTERS[spec]
except KeyError:
return self._formatters["D"]
try:
fmt = orphan_fmt.__class__(self._registry)
spec = get_attr(fmt, "spec", spec)
self._formatters[spec] = fmt
return fmt
except:
return orphan_fmt
from pint.
and then also add the spec attribute to NewFormatter
here
from pint.
On a second thought
spec = get_attr(fmt, "spec", spec)
and adding the spec attribut might not be necessary.
from pint.
I think I understand, thanks! I think I can try to suggest these changes in a PR if that helps.
from pint.
That would be great. I have review the code, it is necessary to add spec = get_attr(fmt, "spec", spec)
and adding the spec attribute to NewFormatter. Let me know if you need help.
from pint.
Related Issues (20)
- Quantity.default_format not initialised HOT 1
- pint 0.24 / numpy 2.0 / python 3.9 issues HOT 19
- Cannot get dimensionality of ratios HOT 1
- Reverse math operators (__rsub_, __radd__ etc.) interfere with non reverse operators of custom classes HOT 1
- [REGR} formatter does not handle negative powers in numerator correctly HOT 1
- What is the best method to get the most human-readable names for units?
- KeyError when using Quantity.check("dimensionless")
- Temperature conversion issue HOT 1
- Get the dimensionality of quantities whose units are ratios of the same unit
- parse_pattern doesn´t parse compound units HOT 4
- degree_Celsius to_compact raises DimensionalityError (Pint 0.23) HOT 1
- 0.24: pytest fails in 4 units HOT 10
- Default format of dimensionless Unit: undocumented change in 0.24 HOT 2
- Another package for ecosystem.rst HOT 4
- Issue using currency symbols ($, €) HOT 4
- pint-convert fails with uncertainties related error if numpy is not installed as well - document numpy dependence or give a better error message HOT 11
- Custom formatters not working with modifiers (Undocumented breaking change in 0.24) HOT 4
- Euro symbol cannot be parsed by the UnitRegistry HOT 1
- Custom formatter can't reformat dimensionless unit HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pint.