Git Product home page Git Product logo

humanize's Introduction

humanize

🚀 Development has moved to https://github.com/python-humanize/humanize 🚀

This modest package contains various common humanization utilities, like turning a number into a fuzzy human-readable duration ("3 minutes ago") or into a human-readable size or throughput. It is localized to:

  • Arabic
  • Bengali
  • Brazilian Portuguese
  • Catalan
  • Danish
  • Dutch
  • European Portuguese
  • Finnish
  • French
  • German
  • Indonesian
  • Italian
  • Japanese
  • Korean
  • Persian
  • Polish
  • Russian
  • Simplified Chinese
  • Slovak
  • Slovenian
  • Spanish
  • Swedish
  • Turkish
  • Ukrainian
  • Vietnamese

API reference

https://python-humanize.readthedocs.io

Usage

Integer humanization

>>> import humanize
>>> humanize.intcomma(12345)
'12,345'
>>> humanize.intword(123455913)
'123.5 million'
>>> humanize.intword(12345591313)
'12.3 billion'
>>> humanize.apnumber(4)
'four'
>>> humanize.apnumber(41)
'41'

Date & time humanization

>>> import humanize
>>> import datetime as dt
>>> humanize.naturalday(dt.datetime.now())
'today'
>>> humanize.naturaldelta(dt.timedelta(seconds=1001))
'16 minutes'
>>> humanize.naturalday(dt.datetime.now() - dt.timedelta(days=1))
'yesterday'
>>> humanize.naturalday(dt.date(2007, 6, 5))
'Jun 05'
>>> humanize.naturaldate(dt.date(2007, 6, 5))
'Jun 05 2007'
>>> humanize.naturaltime(dt.datetime.now() - dt.timedelta(seconds=1))
'a second ago'
>>> humanize.naturaltime(dt.datetime.now() - dt.timedelta(seconds=3600))
'an hour ago'

Precise time delta

>>> import humanize
>>> import datetime as dt
>>> delta = dt.timedelta(seconds=3633, days=2, microseconds=123000)
>>> humanize.precisedelta(delta)
'2 days, 1 hour and 33.12 seconds'
>>> humanize.precisedelta(delta, minimum_unit="microseconds")
'2 days, 1 hour, 33 seconds and 123 milliseconds'
>>> humanize.precisedelta(delta, suppress=["days"], format="%0.4f")
'49 hours and 33.1230 seconds'

Smaller units

If seconds are too large, set minimum_unit to milliseconds or microseconds:

>>> import humanize
>>> import datetime as dt
>>> humanize.naturaldelta(dt.timedelta(seconds=2))
'2 seconds'
>>> delta = dt.timedelta(milliseconds=4)
>>> humanize.naturaldelta(delta)
'a moment'
>>> humanize.naturaldelta(delta, minimum_unit="milliseconds")
'4 milliseconds'
>>> humanize.naturaldelta(delta, minimum_unit="microseconds")
'4 milliseconds'
>>> humanize.naturaltime(delta)
'now'
>>> humanize.naturaltime(delta, minimum_unit="milliseconds")
'4 milliseconds ago'
>>> humanize.naturaltime(delta, minimum_unit="microseconds")
'4 milliseconds ago'

File size humanization

>>> import humanize
>>> humanize.naturalsize(1_000_000)
'1.0 MB'
>>> humanize.naturalsize(1_000_000, binary=True)
'976.6 KiB'
>>> humanize.naturalsize(1_000_000, gnu=True)
'976.6K'

Human-readable floating point numbers

>>> import humanize
>>> humanize.fractional(1/3)
'1/3'
>>> humanize.fractional(1.5)
'1 1/2'
>>> humanize.fractional(0.3)
'3/10'
>>> humanize.fractional(0.333)
'333/1000'
>>> humanize.fractional(1)
'1'

Scientific notation

>>> import humanize
>>> humanize.scientific(0.3)
'3.00 x 10⁻¹'
>>> humanize.scientific(500)
'5.00 x 10²'
>>> humanize.scientific("20000")
'2.00 x 10⁴'
>>> humanize.scientific(1**10)
'1.00 x 10⁰'
>>> humanize.scientific(1**10, precision=1)
'1.0 x 10⁰'
>>> humanize.scientific(1**10, precision=0)
'1 x 10⁰'

Localization

How to change locale at runtime:

>>> import humanize
>>> import datetime as dt
>>> humanize.naturaltime(dt.timedelta(seconds=3))
'3 seconds ago'
>>> _t = humanize.i18n.activate("ru_RU")
>>> humanize.naturaltime(dt.timedelta(seconds=3))
'3 секунды назад'
>>> humanize.i18n.deactivate()
>>> humanize.naturaltime(dt.timedelta(seconds=3))
'3 seconds ago'

You can pass additional parameter path to activate to specify a path to search locales in.

>>> import humanize
>>> humanize.i18n.activate("xx_XX")
<...>
FileNotFoundError: [Errno 2] No translation file found for domain: 'humanize'
>>> humanize.i18n.activate("pt_BR", path="path/to/my/own/translation/")
<gettext.GNUTranslations instance ...>

How to add new phrases to existing locale files:

$ xgettext --from-code=UTF-8 -o humanize.pot -k'_' -k'N_' -k'P_:1c,2' -l python src/humanize/*.py  # extract new phrases
$ msgmerge -U src/humanize/locale/ru_RU/LC_MESSAGES/humanize.po humanize.pot # add them to locale files

How to add a new locale:

$ msginit -i humanize.pot -o humanize/locale/<locale name>/LC_MESSAGES/humanize.po --locale <locale name>

Where <locale name> is a locale abbreviation, eg. en_GB, pt_BR or just ru, fr etc.

List the language at the top of this README.

humanize's People

Contributors

adierebel avatar camposcontentful avatar carterbox avatar chewxy avatar chinacolt avatar dejurin avatar derfel avatar dkrat7 avatar eldipa avatar eteamin avatar gliptak avatar graingert avatar greatbn avatar hugovk avatar jmoiron avatar jordimas avatar jose1711 avatar kpostekk avatar lukaszb avatar martinvw avatar mondeja avatar othrayte avatar phijor avatar rjgpacheco avatar rrtrrrrrrtrf avatar samueljsb avatar scop avatar seriyps avatar sunliwen avatar wasi-master 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  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  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  avatar  avatar  avatar  avatar

Watchers

 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

humanize's Issues

naturaltime returns different results on Windows vs OSX/Linux

Comparing Windows 7 to *nix (OSX/Linux):

import datetime, humanize
humanize.naturaltime(datetime.datetime.now() + datetime.timedelta(days=3))

Returns 3 days from now on Windows, but 2 days from now on the others. I suppose I could interpret either answer as correct, but it feels more correct to say "now + 3 days" = "3 days from now" (siding with Windows, for once). In any case, they should at least agree independent of platform.

reverse humanize. from "1 billion" to in value

This is an amazing lib. Well done!!
I wonder if it is possible a reverse function.

I have a string "1 billion" and I want to convert to int.

Is is doable with the lib? I could not find it in the tests.

Congrats

Positive time duration

humanize.naturaltime(-2) == humanize.naturaltime(2) == '2 seconds ago'

However humanize.naturaltime(2) should be '2 seconds later', or just '2 seconds'.

Actually having the 'ago' makes it even harder when you want to show a duration.
Example: 'Took 2 seconds ago to generate this page', can only be written in the past tense.

Could you please issue a new release?

The old release on pypi humanize-0.5.1 has no translation file for zh_CN.

Thanks a lot : )

Locales listed below for pypi version

Uninstalling humanize-0.5.1:
  lib/python2.7/site-packages/humanize-0.5.1.dist-info/DESCRIPTION.rst
  lib/python2.7/site-packages/humanize-0.5.1.dist-info/INSTALLER
  lib/python2.7/site-packages/humanize-0.5.1.dist-info/METADATA
  lib/python2.7/site-packages/humanize-0.5.1.dist-info/RECORD
  lib/python2.7/site-packages/humanize-0.5.1.dist-info/WHEEL
  lib/python2.7/site-packages/humanize-0.5.1.dist-info/entry_points.txt
  lib/python2.7/site-packages/humanize-0.5.1.dist-info/metadata.json
  lib/python2.7/site-packages/humanize-0.5.1.dist-info/top_level.txt
  lib/python2.7/site-packages/humanize/__init__.py
  lib/python2.7/site-packages/humanize/__init__.pyc
  lib/python2.7/site-packages/humanize/compat.py
  lib/python2.7/site-packages/humanize/compat.pyc
  lib/python2.7/site-packages/humanize/filesize.py
  lib/python2.7/site-packages/humanize/filesize.pyc
  lib/python2.7/site-packages/humanize/i18n.py
  lib/python2.7/site-packages/humanize/i18n.pyc
  lib/python2.7/site-packages/humanize/locale/fr_FR/LC_MESSAGES/humanize.mo
  lib/python2.7/site-packages/humanize/locale/fr_FR/LC_MESSAGES/humanize.po
  lib/python2.7/site-packages/humanize/locale/ko_KR/LC_MESSAGES/humanize.mo
  lib/python2.7/site-packages/humanize/locale/ko_KR/LC_MESSAGES/humanize.po
  lib/python2.7/site-packages/humanize/locale/ru_RU/LC_MESSAGES/humanize.mo
  lib/python2.7/site-packages/humanize/locale/ru_RU/LC_MESSAGES/humanize.po
  lib/python2.7/site-packages/humanize/number.py
  lib/python2.7/site-packages/humanize/number.pyc
  lib/python2.7/site-packages/humanize/time.py
  lib/python2.7/site-packages/humanize/time.pyc
Proceed (y/n)? y


PyInstaller cannot find the humanize distribution

I found this problem when I used the packaging program(pyinstaller) to package a python program.

It seems that there is a problem in retrieving the package. When I change back to the old version(v0.5.5), there is no such problem

I'm a novice. I can't find any specific problems

2020-02-13_192856

Timedelta: "ago" does not always match

I am not a native english speaker, but I think the word "ago" does not match to all timedeltas.

For me "ago" means "before the current moment".

If I want to show the timedelta (duration) of a job which was executed some days in the past, and this job took 10 seconds, then "10 seconds ago" does not match.

What do you think?

Setup fails on windows

On my Windows system : pip install humanize (or python setup.py install on sources) fails with this error :
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 2017: character maps to <undefined>
Full stack trace here

I have naively fixed that by replacing this line by :
long_description=open('README.rst', 'r', encoding='UTF8').read(),
I don't know if it's a great solution but it worked for me.

New maintainer?

@jmoiron Hi Jason! Thank you very much for this project!

It's been three years since an update, and there's quite a few PRs. This project is quite widely used (560k downloads last month according to https://pypistats.org/packages/humanize!), and it'd be great to keep things ticking over.

I understand if you've moved on and have other interests. Please would you consider giving merge and PyPI rights to one or more extra maintainers?

I'd like to volunteer, especially to help with some of the maintenance tasks and to get a new release out. I could modernise the codebase for current Python versions, add testing with pytest and linting on GitHub Actions (I've made a start in #84).

I've gone through the PRs and approved some I think are good to merge, and commented some others that could use a bit extra work.

Additionally to consider, a transfer to https://jazzband.co, which provides additional maintainer backup.

What do you think?

Again, thank you for this project!

Edit: Also emailed this to Jason.

Rounding

One oddity to me is the rounding. While I can understand that

humanize.naturaltime(2*365*24*60*60 - 1)

is 1 year, 11 months ago and not 2 years ago, because the year is not complete yet and we don't celebrate birthdays early ("how long ago was it?" - "2 years?" - "not yet!"), my intuitive expectation of

humanize.naturaldelta(2*365*24*60*60 - 1)

is actually 2 years - because with deltas ("how long did it take?"), I feel rounding is much more natural.

So for 101_943 / 1_000_000, I'd probably expect 102 milliseconds.

Originally posted by @bersbersbers in #75 (comment)

Negative Sizes Only Show In Bytes

When using naturalsize with negative values (I wish to display a change in file size), you only get bytes:

>>> In[4] import humanize
>>> In[5] humanize.naturalsize(123456)
>>> Out[5]: '123.5 kB'
>>> In[6] humanize.naturalsize(-123456)
>>> Out[6]: '-123456 Bytes'

Is it possible to get these values shown in the same manner as positive values?

Unit abbreviations for intword: print '22k' instead of '22 thousand'

Good day,

In some contexts, a human-friendly version of numbers might include abbreviations for units (like 'k', 'M', 'G', etc).
While humanize provides a special version for file sizes (and distances are pending), many other areas are not covered:

  • Prices: instead of '$3.10 million', print '$3.10M'
  • Scientific units: '100kPA' for pressure; '3kW'
    and so on.

Would it be possible to answer the following questions:

  1. Would the owners of the humanize mind if I added this functionality?

  2. If the feature seems acceptable, what would be the preferred API to provide access to it?
    I could see at least a few ways:

  • Add a new method intchar(value, format).
    In this case, the code would look like
intchar(3120123, format='$%.1f') --> '$3.1M'
intchar(22123, format='%.1fB') --> '22.0kB'
  • Add a parameter to intword(value, format="%.1f", abbreviated_units=False)

Thank you!

No attribute naturaldelta (PyPi 0.5 version)

First of all many thanks for this little gem of a library, I really like it!

When I do:

>>> from humanize import *

(which I know I shouldn't be doing) I get:

AttributeError: 'module' object has no attribute 'naturaldelta'

This seems to have been fixed in the latest version, but not in the PyPi 0.5 version.

function to print timedeltas exactly

Hi,
I find myself using a function regularly that prints a time delta as "4 hours, 3 minutes, and 15.3 seconds". Is this a function you'd be interested in adding to your library?

I'd rather add it to a common library rather than copy and pasting it the whole time.

If you want it I'll open a PR with the requisite code.

Cheers,

Chris

naturalsize() contains a very common but serious programming bug

I just finished writing a proper "human bytes" function. When I was done, I did a Google search and actually found this project but noticed that you have the same major bug that the majority of other programmers in the world have. Since you've created a library that people reuse, it's important that you fix the bug in the library.

Here's the bugged library file:

https://github.com/jmoiron/humanize/blob/e2b217f2407a4f16b99516caf8934a12b16d58de/src/humanize/filesize.py

Here's the code I posted on a throwaway stackoverflow account. It explains the bug and provides a solution. You can pick it apart and adapt it for your project. Good luck! :-)

https://stackoverflow.com/a/63839503/8874388

Works with naïve datetimes

Hi! I’m not currently a user of the library but it looks interesting. I noticed that functions use datetime.now() as basis for relative times and such, which can easily lead to issues. I tend to try hard to avoid timezone-less dates and datetimes, and always work in UTC (just like one wants to work with unicode objects instead of byte strings). I would suggest that humanize should reject naïve date(time)s, or (less drastic) that functions that work with date use the argument’s timezone in the _now function.

precisedelta is not included in pypi package

What did you do?

Installed humanize & attempted to use precisedelta function

What did you expect to happen?

For the function to exist in the package

What actually happened?

The function does not exist in the time.py module & fails to import

What versions are you using?

  • OS: Win 10
  • Python: 3.7.4
  • Humanize: 2.5.0

Please include code that reproduces the issue.

>>> import humanize
>>> import datetime as dt
>>> humanize.time.precisedelta(dt.date.today() - dt.date(2020,7,1))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'humanize.time' has no attribute 'precisedelta'
>>> humanize.precisedelta(dt.date.today() - dt.date(2020,7,1))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'humanize' has no attribute 'precisedelta'

Drop support for Python 2.7

Five years after the last release, humanize 1.0.0 has now been released, supporting Python 2.7 and 3.5-3.8.

Since 2020-01-01, Python 2.7 is now EOL and has relatively low download numbers. Here's the pip installs for humanize from PyPI for January 2020:

category percent downloads
3.7 24.58% 157,128
3.6 24.56% 157,052
2.7 22.78% 145,633
3.4 12.98% 82,976
3.5 10.77% 68,839
3.8 2.58% 16,524
null 1.74% 11,109
3.9 0.01% 74
2.6 0.00% 15
3.3 0.00% 2
Total 639,352

Source: pip install -U pypistats && pypistats python_minor humanize --last-month

The next release (short of any important bug fixes from 1.0.0) will drop support for Python 2 and will be version 2.0.0.

The python_requires metadata will help those with modern pip (v9+) get the newest version of humanize that supports their Python version.

1024*1024*1024 = 1.1 GB?

What did you do?

>>> humanize.naturalsize(1024*1024*1024)

What did you expect to happen?

>>> humanize.naturalsize(1024*1024*1024)
'1.0 GB'

What actually happened?

>>> humanize.naturalsize(1024*1024*1024)
'1.1 GB'

What versions are you using?

>>> humanize.__version__
'1.0.0'
  • OS: Linux
  • Python: 2.7
  • Humanize: 1.0.0

[Request] Humanizing distances

What I want to do

Humanize distances between two points (see Distance object https://docs.djangoproject.com/en/3.1/ref/contrib/gis/measure/#distance)

Why it makes sense

For short distances it makes sense to have approximations in meters, for longer distances in kilometres or miles. It is also weird-looking to show the exact distance, e.g. 2392.324553 km. Then we have the locale issue where some countries prefer miles over kilometers.

I have been looking for some formulae online but can't find any best practices or libraries for this. I noticed that maps applications have this behaviour, but I can't find any specs to it.

Do you think such a function would be useful in humanize? Do you know of any specs/best practices? I am more than happy to do the implementation, if you think it is worth it, and if you can help with the full definition of this task.

Drop support for Python 3.5

CPython 3.5 reaches end-of-life on 2020-09-13.

Humanize will also drop support for Python 3.5 around the same time.

I'm considering this won't need a major version bump, as the python_requires will be updated so people still on 3.5 will get the last release that did support it.

-    python_requires=">=3.5",
+    python_requires=">=3.6",
     # Get strings from https://pypi.org/pypi?%3Aaction=list_classifiers
     classifiers=[
         "Development Status :: 5 - Production/Stable",
         "Intended Audience :: Developers",
         "License :: OSI Approved :: MIT License",
         "Operating System :: OS Independent",
         "Programming Language :: Python",
         "Programming Language :: Python :: 3",
-        "Programming Language :: Python :: 3.5",
         "Programming Language :: Python :: 3.6",
         "Programming Language :: Python :: 3.7",
         "Programming Language :: Python :: 3.8",
         "Programming Language :: Python :: 3 :: Only",

Description without documentation

Problem: Turn a saying suchas 3 minutes ago into something readable by a program.... this is what this libraries original intention was to solve, however, there is ZERO documentation on how to do so.

Incorrect expected value of `fractional(0.333)` in the readme

What did you do?

I ran byexample to verify the examples in the readme:

byexample -l python README.md

I also confirmed the issue running the example in a python console.

What did you expect to happen?

The readme says:

>>> humanize.fractional(0.333)
'1/3'

What actually happened?

Instead of '1/3' it returns '333/1000'

The value returned is probably the correct one, I think that the readme should be updated.

What versions are you using?

  • OS: Debian 9
  • Python: Python 3.5
  • Humanize: master

precisedelta with minimum unit seconds fails when seconds is a very small value

What did you do?

Calculated a small delta.

import humanize
from datetime import timedelta
duration_seconds = 1e-06       # A small value, or 0
delta = timedelta(seconds=duration_seconds)
output = humanize.precisedelta(delta, minimum_unit="minutes")
print(output)

What did you expect to happen?

Output would be 0 seconds.

Alternatively, a better error message or a warning in the documentation would be helpful.

What actually happened?

>       tail = texts[-1]
E       IndexError: list index out of range

What versions are you using?

  • OS: ubuntu
  • Python: 3.6.12
  • Humanize: 2.6.0

Test contains invalid format string

The linked lines in tests/time.py contain the format string %Y.%M.%D. This causes the test to fail.

%M is "Minute as a zero-padded decimal number." and %D doesn't exist.

The correct format is %Y.%m.%d.

$ nosetests
.......E.....
======================================================================
ERROR: test_naturalday (tests.TimeTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "c:\Users\...\tests\time.py", line 269, in test_naturalday
    date(1982, 6, 27).strftime('%Y.%M.%D'), None, "Not a date at all.",
ValueError: Invalid format string

----------------------------------------------------------------------
Ran 13 tests in 0.056s

FAILED (errors=1)

Wrong french intword values

Using fr_FR, as of 10**12 (english "trillion", french "billion"), the intword function returns wrong results. See https://en.wikipedia.org/wiki/Long_and_short_scales

>>> humanize.i18n.activate('fr_FR')
<gettext.GNUTranslations instance at 0x7f7eeb455e60>
>>> humanize.intword(10**6)
'1.0 million'
>>> humanize.intword(10**9)
'1.0 milliard'
>>> humanize.intword(10**12)
'1.0 trillion'
>>> humanize.intword(10**15)
'1.0 quadrillion'

naturaldate returns ambiguous values

>>> import humanize
>>> from datetime import datetime, timedelta
>>> humanize.naturaldate(datetime.now()-timedelta(3))
'Jan 15'
>>> humanize.naturaldate(datetime.now()+timedelta(362))
'Jan 15'

I'd suggest to add the year for all dates that are more than about five months away. This would lead to the following output:

date naturaldate (executed in Jan 2015)
2014-08-20 Aug 20
2015-08-20 Aug 20 2015
2014-06-20 Jun 20 2014
2015-06-20 Jun 20

(Even when only used for dates that are necessarily in the past, like "comment posted on ...", the current behaviour is not perfect: If I read "Jan 19" on Jan 18, 2015, I won't not assume it means Jan 19, 2014.)

[Request] Max Error parameter for rounding

The examples I am providing are based on the following use case, but I believe this applies more generally across the tool. I am using naturaldelta to describe the duration of a route (for example Miami, FL to Atlanta, GA is 9 hours).

One concern is the rounding (2 hours 59 minutes becomes 2 hours), but #154 seems to resolve that concern.

My second concern is the precision in the range of about 1-10 hours. Currently, 2 hours 29 minutes becomes 2 hours. I feel like that misrepresents the actual duration given that it is off by 20%. I am wondering if "2 and a half hours" would be a better result. I'm not sure on the most natural language way to write this, "2 hours 30 minutes" is probably the most generalized form.

Initially, I was thinking this would be connected to the rounding, perhaps as an alternative option rounding to half values. So 45 minutes to 1 hour 15 minutes would round to 1 hour. 1 hour 15 minutes to 1 hour 45 minutes would round to 1.5 hour. However, thinking more broadly different applications will have different precision requirements. Allowing users to set a max_error and then using that to determine the best rounding would be a good solution.

So considering a max_error of 10%, 8,880 seconds (2 hours, 28 minutes) would become 2 hours and 30 minutes. This is because 2 hours is 19% off (greater than 10%). So we drop to the next smallest unit (30 minutes) and that results in an error of 1.4%, so we stop here. Now thinking about 9,660 seconds (2 hours 41 minutes) and a max error of 5%. This gets rounded to 3 hours, but has an error of 12%, so we cut to the next increment (30 minutes) and round to 2 hours 30 minutes. That has an error of 7%, so still too much. The next increment would be 15 minutes, so we round to 2 hours 45 minutes and stop there with an error of 2%.

Using a max_error parameter also resolves the statement I made earlier "My second concern is the precision in the range of about 1-10 hours". From this statement I can see that I care about the precision of 30 minutes up to 9 hours 30 minutes, so my desired precision is 5% (0.5 hour/9.5 hour). Beyond that, I would only get hours.

I'm thinking these increments (for timedelta) would be:

  • millenium
  • century
  • decade
  • years
  • 6 months
  • months
  • days
  • hours
  • 30 minutes
  • 15 minutes
  • 5 minutes
  • 1 minute
  • 30 seconds
  • 15 seconds
  • seconds
  • milliseconds
  • microseconds

Other functions would need to have their own increments developed.

Support milliseconds, microseconds etc.

If you run something for a minute, humanize is great. If you want to tell the user what you did in that time (100.000 things), and then want to brag about how fast that is (a moment per thing?), humanize is not super-great any more :)

DeprecationWarning due to invalid escape sequences

Using raw string or escaping them helps.

./humanize/number.py:48: DeprecationWarning: invalid escape sequence \d
  new = re.sub("^(-?\d+)(\d{3})", '\g<1>,\g<2>', orig)
./humanize/number.py:48: DeprecationWarning: invalid escape sequence \g
  new = re.sub("^(-?\d+)(\d{3})", '\g<1>,\g<2>', orig)

Missing year on older dates

If a date is more than a year in the past, the year (number) should be included in the humanized date.
Current (broken) functionality:

>>> import datetime
>>> import humanize
>>> humanize.naturalday(datetime.datetime.now() - datetime.timedelta(days=10))
'Apr 01'
>>> humanize.naturalday(datetime.datetime.now() - datetime.timedelta(days=1000))
'Jul 16'

humanize.apnumber(0) should return zero

humanize.appnumber returns 0 for 0, while (I think) it should return 'zero':

>>> import humanize
>>> humanize.apnumber(0)
'0'
>>> humanize.apnumber(1)
'one'
>>> humanize.apnumber(2)
'two'
>>>

Multiple Codecov comments on PRs

Hi @jmoiron!

There's an odd issue with, for example, #117 (comment) and #120 (comment), in that there are multiple Codecov comments, plus from an unknown username.

Codecov support suggested:

Can I ask you to revoke and add back the Codecov app on GitHub, or add if if you don’t have it? Duplicate comments from both Codecov and the user are usually caused by confused permissions on our end.

Please could you check it at https://github.com/jmoiron/humanize/settings/installations? Or alternatively give me access to that?

Thank you!

'decimal': ('kB'), the 'k' must be upper.

suffixes = {
    'decimal': ('kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'),
    'binary': ('KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'),
    'gnu': "KMGTPEZY",
}

==> the first letter of 'kB', 'k' must be upper.

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.