freeze Documentation Release 0.7.0alpha Jean-Louis Fuchs

Similar documents
streamio Documentation

Beyond Blocks: Python Session #1

DEBUGGING TIPS. 1 Introduction COMPUTER SCIENCE 61A

redis-lua Documentation

PyTrie Documentation. Release 0.3. George Sakkis

Dogeon Documentation. Release Lin Ju

tolerance Documentation

eoddata-client Documentation

Dictionaries. By- Neha Tyagi PGT CS KV 5 Jaipur II Shift Jaipur Region. Based on CBSE Curriculum Class -11. Neha Tyagi, KV 5 Jaipur II Shift

PyZabbixObj Documentation

Script language: Python Data structures

python-anyvcs Documentation

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Kiki Documentation. Release 0.7a1. Stephen Burrows

PYTHON FOR MEDICAL PHYSICISTS. Radiation Oncology Medical Physics Cancer Care Services, Royal Brisbane & Women s Hospital

bottle-rest Release 0.5.0

Kaiso Documentation. Release 0.1-dev. onefinestay

tld Documentation Release 0.9 Artur Barseghyan

Unicum Documentation. Release alpha. Deutsche Postbank AG

CS 61A Interpreters, Tail Calls, Macros, Streams, Iterators. Spring 2019 Guerrilla Section 5: April 20, Interpreters.

django-oauth2-provider Documentation

iris-grib Documentation

Marshmallow-Mongoengine Documentation

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

maya-cmds-help Documentation

Archan. Release 2.0.1

Python review. 1 Python basics. References. CS 234 Naomi Nishimura

linkgrabber Documentation

starbase Documentation

Baron Documentation. Release 0.6. Laurent Peuch

pyprika Documentation

Sage Reference Manual: Python technicalities

Lecture 15 Binary Search Trees

Devirtualize Documentation

pyramid_assetmutator Documentation

Genetic Documentation

DynamiX Documentation

Python Reference (The Right Way) Documentation

Software tools for Classical Planning Artificial Intelligence Qatar Fall 2018 Sep 20, 2018

EVE Market Data Structures Documentation

CSC148, Lab #4. General rules. Overview. Tracing recursion. Greatest Common Denominator GCD

Today: Revisit some objects. Programming Languages. Key data structure: Dictionaries. Using Dictionaries. CSE 130 : Winter 2009

treelib Documentation

behave-webdriver Documentation

pygtrie Release Jul 03, 2017

StratumGS Documentation

: Intro Programming for Scientists and Engineers Final Exam

picrawler Documentation

YouTube API Wrapper Documentation

CS150 - Sample Final

databuild Documentation

RPLidar Documentation

Lists, Tuples and Dictionaries. HORT Lecture 10 Instructor: Kranthi Varala

ramp Documentation Release 0.1 Ken Van Haren

Begin at the beginning

BRONX COMMUNITY COLLEGE of the City University of New York DEPARTMENT OF MATHEMATICS AND COMPUTER SCIENCE. Sample Final Exam

python-aspectlib Release 0.5.0

solrq Documentation Release Michał Jaworski

python-aspectlib Release 0.4.1

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression


LECTURE 3 Python Basics Part 2

treelib Documentation

Clang Static Analyzer Documentation

dragonfluid Documentation

TPS Documentation. Release Thomas Roten

dota2api Documentation

Home Assistant Documentation

CNRS ANF PYTHON Objects everywhere

Advanced Algorithms and Computational Models (module A)

Basilisk Documentation

RiotWatcher Documentation

python-docker-machine Documentation

CSCA08 Winter Week 12: Exceptions & Testing. Marzieh Ahmadzadeh, Brian Harrington University of Toronto Scarborough

Python Finite State Machine. Release 0.1.5

Principles of Functional Programming

Iterators & Generators

Faculty of Science FINAL EXAMINATION

ipython-gremlin Documentation

Python wrapper for Viscosity.app Documentation

Page. User. Sorting Mini-HOW TO. Search Titles Text. More Actions: HowTo Sorting. HowTo/Sorting

bzz Documentation Release Rafael Floriano and Bernardo Heynemann

Python State Machine Documentation

MyVariant.py Documentation

Python Release September 11, 2014

ArangoDB Python Driver Documentation

pyshk Documentation Release Jeremy Low

Community detection for NetworkX Documentation

CSC148 Recipe for Designing Classes

Working with Lists 4

FriendlyShell Documentation

Tail Recursion: Factorial. Begin at the beginning. How does it execute? Tail recursion. Tail recursive factorial. Tail recursive factorial

MicroPython Development Documentation Documentation

Torndb Release 0.3 Aug 30, 2017

django-crucrudile Documentation

pybdg Documentation Release 1.0.dev2 Outernet Inc

Multiple and Virtual Inheritance in C++

Side note: Tail Recursion. Begin at the beginning. Side note: Tail Recursion. Base Types. Base Type: int. Base Type: int

Lecture #15: Generic Functions and Expressivity. Last modified: Wed Mar 1 15:51: CS61A: Lecture #16 1

Data Handing in Python

Transcription:

freeze Documentation Release 0.7.0alpha Jean-Louis Fuchs April 10, 2014

Contents i

ii

freeze.freeze(data_structure) Freeze tries to convert any data-structure in a hierarchy of tuples. freeze.object_to_items(data_structure) Converts a object to a items list respecting also slots. freeze.dump(data_structure) Dump will create a human readable version of your data-structure. freeze.tree_diff_assert(a, b[, n, sort]) User tree_diff() to assert a equals b. freeze.stable_hash(data_structure) Stable hash does: hash(recursive_sort(freeze(data_structure))) freeze.recursive_hash(data_structure) Recursive hash does: hash(freeze(data_structure)) freeze.tree_diff(a, b[, n, sort]) Dump any data-structure or object, traverse it depth-first in-order and appl freeze.vformat(*args, **kwargs) A pformat wrapper that produces narrow representations of data-structure freeze.transparent_repr(string) The result is repr transparent. freeze.traverse_frozen_data(data_structure) Yields the leaves of the frozen data-structure pre-order. freeze.traversalbasedreprcompare(payload) Implements the comparison method for frozen data-structures based on tra Freeze the state of data-structures and objects for data-analysis or testing (diffing data-structures). Frozen datastructures consist of only tuples and these are comparable/sortable/hashable. The freeze() function can be used for many purposes for example implement hash () for your complex object very fast. dump() is intended for testing and analysis. Authors: Jean-Louis Fuchs <ganwell@fangorn.ch> https://github.com/ganwell Run doctests with python -m freeze freeze.freeze(data_structure) Freeze tries to convert any data-structure in a hierarchy of tuples. Tuples are comparable/sortable/hashable, you can use this with with recursive_sort(). freeze has no recursion detection. Parameters data_structure The structure to convert. >>> recursive_sort(freeze(_testclass())) (( a, huhu ), ( sub, (( a, slot ), ( b, (1, (1, 2, 3), 2, 3))))) >>> dump((none, (None, None))) (None, (None, None)) freeze.object_to_items(data_structure) Converts a object to a items list respecting also slots. Use dict(object_to_items(obj)) to get a dictionary. freeze.dump(data_structure) Dump will create a human readable version of your data-structure. It will try to dump almost anything, it has recursion detection and will try to display the recursion in a meaningful way. Parameters data_structure The structure to convert. When you freeze only content counts, same content same hash >>> a = hash(freeze(_testclass())) >>> b = hash(freeze(_testclass())) >>> b == a >>> a = freeze(_testclass()) >>> b = freeze(_testclass()) >>> b == a >>> x = _TestClass() >>> a = freeze(dump(x)) >>> b = freeze(dump(x)) Contents 1

>>> b == a When you dump-freeze only content/type counts, same content/type same hash Two object of the same type with same content will be equal Two object of the different type with same content will be different >>> a = hash(freeze(dump(_testclass()))) >>> b = hash(freeze(dump(_testclass()))) >>> b == a >>> a = freeze(dump(_testclass())) >>> b = freeze(dump(_testclass())) >>> b == a >>> a = hash(freeze(dump(_testclass()))) >>> b = hash(freeze(dump(_testclass2()))) >>> b!= a >>> a = freeze(dump(_testclass())) >>> b = freeze(dump(_testclass2())) >>> b!= a >>> _py2_to_py3(vformat(dump([1, { a : b }]))) [1, ["<class dict >", { a : b }]] >>> vformat(recursive_sort(dump(_testclass()))) ["<class freeze._testclass >", (( a, huhu ), ( sub, ["<class freeze._testslots >", (( a, slot ), ( b, (1, (1, 2, 3), 2, 3)))]))] >>> a = _TestSlots() >>> b = [a, 1, 2, [a, "banane"]] >>> _no_null_x(vformat(dump(b))) { a : slot, b : [1, 2, 3, (1, 2, 3)]}], 2 Contents

1, 2, banane ]] >>> a = [1, 2] >>> _no_null_x(vformat(dump((a, (a, a))))) [1, 2]], >>> recursive_sort(dump(freeze(_testclass()))) (( a, huhu ), ((( a, slot ), ( b, (1, (1, 2, 3), 2, 3))), sub )) >>> dump((none, (None, None))) (None, (None, None)) freeze.tree_diff_assert(a, b, n=5, sort=false) User tree_diff() to assert a equals b. Dump any data-structure or object, traverse it depth-first and apply a unified diff, to display the result. Parameters a data_structure a b data_structure b n (int) lines of context sort sort the data-structure ATTENTION: Sorting means changing the data-structure. The test-result may differ. But in case of dictionaries the results become comparable because the sorting negates the hash-algorithms de-sorting. >>> a = [... [3, 4],... { a : [3, { w : set([4, tree, frozenset([3,5,2])])}]}, >>> b = [... [4, 3],... { a : [3, { w : set([4, 3, frozenset([2,5,3])])}]}, >>> try:... tree_diff_assert(a, b, sort=)... except:... "GOT IT" GOT IT >>> a = [... [3, 4],... { a : [3, { w : set([4, 3, frozenset([3,5,2])])}]}, >>> b = [... [4, 3],... { a : [3, { w : set([ 3, 4, frozenset([2,5,3])])}]}, Contents 3

>>> tree_diff_assert(a, b, sort=) >>> a = [... [3, 4],... { a : [3, { w : set([4, 3, frozenset([3,5,2])])}]}, >>> b = [... [4, 3],... { a : [3, { w : set([ 3, 4, frozenset([2,5,3])])}]}, >>> try:... tree_diff_assert(a, b, sort=false)... except:... "GOT IT" GOT IT freeze.stable_hash(data_structure) Stable hash does: hash(recursive_sort(freeze(data_structure))) >>> a = stable_hash(_testclass()) >>> b = stable_hash(_testclass()) >>> a == b freeze.recursive_hash(data_structure) Recursive hash does: hash(freeze(data_structure)) >>> a = recursive_hash(_testclass()) >>> b = recursive_hash(_testclass()) >>> a == b freeze.tree_diff(a, b, n=5, sort=false) Dump any data-structure or object, traverse it depth-first in-order and apply a unified diff. Depth-first in-order is just like structure would be printed. Parameters a data_structure a b data_structure b n (int) lines of context sort sort the data-structure ATTENTION: Sorting means changing the data-structure. The test-result may differ. But in case of dictionaries the results become comparable because the sorting negates the hash-algorithms de-sorting. >>> a = recursive_sort(freeze([... [3, 4],... { a : [3, { w : set([4, 3, frozenset([3,5,2])])}]}, )) 4 Contents

>>> b = recursive_sort(freeze([... [7, 3],... { a : [3, { w : set([4, 3, frozenset([2,5,3])])}]}, )) >>> transparent_repr("\n".join(tree_diff(a, b).split("\n")[2:])) @@ -7,6 +7,6 @@ w ),), 3), a ),), a, (3, - 4)) + 7)) >>> a = [... [3, 4],... { a : [3, { w : set([4, 3, frozenset([3,5,2])])}]}, >>> b = [... [7, 3],... { a : [3, { w : set([4, 3, frozenset([2,5,3])])}]}, >>> transparent_repr("\n".join(... tree_diff(a, b, sort=... ).split("\n")[2:])) @@ -11,6 +11,6 @@ 3, 4)]),)], 3)),)], a, (3, - 4)) + 7)) freeze.vformat(*args, **kwargs) A pformat wrapper that produces narrow representations of data-structures. The result is repr transparent. Non-printable characters won t be escaped freeze.transparent_repr(string) The result is repr transparent. Non-printable characters won t be escaped >>> transparent_repr(3) 3 freeze.traverse_frozen_data(data_structure) Yields the leaves of the frozen data-structure pre-order. It will produce the same order as one would write the data-structure. class freeze.traversalbasedreprcompare(payload) Implements the comparison method for frozen data-structures based on traverse_frozen_data. Contents 5

>>> cm = TraversalBasedReprCompare >>> cm(3) < cm(4) >>> cm(4) > cm(3) >>> cm(3) > cm(4) False >>> cm(3) == cm(3) >>> cm(3) == cm(4) False >>> cm((3, 3)) > cm((3,)) >>> cm((3, 3)) == cm((3, 3)) >>> cm((3,)) > cm((3, 3)) False >>> cm((3,)) == cm((3, 3)) False 6 Contents

CHAPTER 1 Indices and tables genindex modindex search 7

8 Chapter 1. Indices and tables

Python Module Index f freeze,?? 9