GithubHelp home page GithubHelp logo

temporenc / temporenc-python Goto Github PK

View Code? Open in Web Editor NEW
12.0 3.0 1.0 111 KB

python library for the temporenc format

Home Page: http://temporenc.readthedocs.org/

License: Other

Python 99.36% Makefile 0.64%
python datetime date time encoding binaryformat library temporenc

temporenc-python's Introduction

temporenc-python's People

Contributors

wbolster avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

Forkers

danome

temporenc-python's Issues

packing time zone aware datetime.time() instances fails

>>> temporenc.packb(datetime.datetime.now(datetime.timezone.utc).timetz())
Traceback (most recent call last):
  File "<ipython-input-11-4382b914e27d>", line 1, in <module>
    temporenc.packb(datetime.datetime.now(datetime.timezone.utc).timetz())
  File "/home/uws/Projects/temporenc/temporenc-python/temporenc/temporenc.py", line 544, in packb
    value = value - delta
TypeError: unsupported operand type(s) for -: 'datetime.time' and 'datetime.timedelta'

The standard library doesn't support this, it seems. From https://docs.python.org/3.4/library/datetime.html#datetime.timedelta:

"[...] although note that arithmetic on time objects is not supported."

Since we're working with fixed offsets anyway, it should be possible to do the arithmetic ourselves before encoding.

maybe add shortcuts for unpacking directly to native types

Perhaps it makes sense to have shortcuts to unpack directly to a datetime.datetime (and siblings), instead of going through an intermediate Moment instance. This would be mostly for performance reasons, since unpackb(b).datetime() is already pretty short and idiomatic.

Demonstrate conversion from/to common date/time formats

Hi,

I accidentally stumbled across a StackOverflow article where you recommend temporenc and it immediately caught my attention as I generally like to use "normalized" date formats (instead of obscure epoch-based formats) and I am currently contemplating if I want to go with temporenc (I'm quite positive, though).

I immediately found that I, and probably everybody else, need algorithms for converting to and from the following common formats: Windows 64-bit time stamps, Unix 32-bit time stamps, ISO this-and-that long string representations, etc.

It would be a great help for everybody who contemplate using your new format, I think, if you could research and provide sample code for converting forth and back between the most commonly used formats.

You may argue that this is not your responsibility, which I'd sort of agree with, but I think it could help the adoption rate of your new format quite a bit, if you (or somebody else) supplied the above.

I found a couple of links of relevance to this request:

  1. Microsoft blog.
  2. Python code.
  3. date decode using Python.

Cheers,
Archfrog

Python optimization?

I made a basic benchmark for the python implementation. I just used the first thing I found when searching for "python benchmark"; maybe there are better options?

Anyway, the upshot is that on my machine python generally takes about 100-200 microseconds to serialize or deserialize 100 objects (so a couple of microseconds on average per object, though that's not really how it works). This is probably fine in practice, so I don't want to give the impression that I'm saying this is an urgent problem or anything.

Now for the totally unfair comparison. My rust implementation has been built for speed: it only ever allocates on the stack, is in a language with a fast compiler, etc, so it's not doing the same job as the Python code is. But, it is fast. Encoding and decoding objects (into pre-existing buffers) for the same 100 objects takes between 200 and 1400 nanoseconds, if my benchmarks are to be believed.

So, I thought it might be interesting to explore if it's possible to have an alternate back-end for the Python code that uses the Rust code for byte wrangling. I definitely want to keep a painless, easy-to-understand Python implementation for users who can't compile Rust code and for all the interop value of having another independent implementation. On the other hand, if this is something that's interesting to you, and there are things I can do in the Rust codebase (or not do) to make such a thing easy and/or feasible and that don't require regular Rust users to bend over backwards or anything like that, then it seems like it could be fun. Hypothetically the interop between Rust and Python's C API should not be a huge obstacle. I've done Rust/C interop in other projects and it's fine.

There's still more I need to build in the Rust library for this to be feasible, like polymorphic deserialization (where you don't already know what type you're about to deserialize), but I wanted to float the idea now just in case.

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.