Custom Query (121 matches)
Results (7 - 9 of 121)
| Ticket | Resolution | Summary | Owner | Reporter |
|---|---|---|---|---|
| #7 | fixed | doubles represented as .nan | xi | anonymous |
| Description |
in python2.3.5: yaml.dump(10.24) will provide .nan the source of it lay in the python 2.3 .nan handling, it is equal to any float: inf_value = 1e300000 nan = inf_value/inf_value nan == 5.6 and nan = 5006.78 --> True after i did change a line in representer.py from: elif data == self.nan_value or data != data: to: elif str(data) == str(self.nan_value) or data != data: yaml.dump -- provide correct handling of floats. thanks .... |
|||
| #8 | fixed | Comparison operations fail with floats (NaN and +/- Inf) in PyYAML3000 on WinXP (SP2) | xi | Peter Murphy (pkmurphy@… |
| Description |
This is what happens when you run the test suite under WinXP (SP2) and Python 2.4: C:\pyyaml\trunk>python tests/test_build.py
..............................................................................................................................................................................................................................................................................F..........................E........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................E..........................E............................................................................................................................................................
======================================================================
ERROR: testTypes_float_representer_2_3_bug (test_constructor.TestConstructorTypes)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\pyyaml\trunk\tests\test_appliance.py", line 28, in test_method
getattr(self, '_'+method_name)(test, *filenames)
File "C:\pyyaml\trunk\tests\test_constructor.py", line 249, in _testTypes
data1 = list(load_all(file(data_filename, 'rb'), Loader=MyLoader))
File "build/lib\yaml\__init__.py", line 52, in load_all
yield loader.get_data()
File "build/lib\yaml\constructor.py", line 41, in get_data
return self.construct_document(self.get_node())
File "build/lib\yaml\constructor.py", line 49, in construct_document
data = self.construct_object(node)
File "build/lib\yaml\constructor.py", line 86, in construct_object
data = constructor(node)
File "build/lib\yaml\constructor.py", line 63, in <lambda>
constructor = lambda node: self.yaml_constructors[node.tag](self, node)
File "build/lib\yaml\constructor.py", line 358, in construct_yaml_map
return self.construct_mapping(node)
File "build/lib\yaml\constructor.py", line 153, in construct_mapping
"found duplicate key", key_node.start_mark)
ConstructorError: while constructing a mapping
in "tests/data\float-representer-2.3-bug.data", line 2, column 1
found duplicate key
in "tests/data\float-representer-2.3-bug.data", line 3, column 1
======================================================================
ERROR: testTypes_construct_float (test_representer.TestRepresenterTypes)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\pyyaml\trunk\tests\test_appliance.py", line 28, in test_method
getattr(self, '_'+method_name)(test, *filenames)
File "C:\pyyaml\trunk\tests\test_representer.py", line 15, in _testTypes
data2 = load(output, Loader=MyLoader)
File "build/lib\yaml\__init__.py", line 61, in load
return loader.get_data()
File "build/lib\yaml\constructor.py", line 41, in get_data
return self.construct_document(self.get_node())
File "build/lib\yaml\constructor.py", line 49, in construct_document
data = self.construct_object(node)
File "build/lib\yaml\constructor.py", line 86, in construct_object
data = constructor(node)
File "build/lib\yaml\constructor.py", line 63, in <lambda>
constructor = lambda node: self.yaml_constructors[node.tag](self, node)
File "build/lib\yaml\constructor.py", line 358, in construct_yaml_map
return self.construct_mapping(node)
File "build/lib\yaml\constructor.py", line 154, in construct_mapping
value = self.construct_object(node.value[key_node])
File "build/lib\yaml\constructor.py", line 86, in construct_object
data = constructor(node)
File "build/lib\yaml\constructor.py", line 63, in <lambda>
constructor = lam
DATA:
canonical: 6.8523015e+5
exponential: 685.230_15e+03
fixed: 685_230.15
sexagesimal: 190:20:30.15
negative infinity: -.inf
not a number: .NaN
CODE:
{
"canonical": 685230.15,
"exponential": 685230.15,
"fixed": 685230.15,
"sexagesimal": 685230.15,
"negative infinity": -1e300000,
"not a number": 1e300000/1e300000,
}
NATIVES1: [("'canonical'", 685230.15000000002), ("'exponential'", 685230.15000000002), ("'fixed'", 685230.15000000002), ("'negative infinity'", -1.0), ("'not a number'", 1.0), ("'sexagesimal'", 685230.15000000002)]
NATIVES2: [("'canonical'", 685230.15000000002), ("'exponential'", 685230.15000000002), ("'fixed'", 685230.15000000002), ("'negative infinity'", -1.#INF), ("'not a number'", -1.#IND), ("'sexagesimal'", 685230.15000000002)]
DATA:
#0.0: # hash(0) == hash(nan) and 0 == nan in Python 2.3
1.0: 1
+.inf: 10
-.inf: -10
.nan: 100
CODE:
{
# 0.0: 0,
1.0: 1,
1e300000: +10,
-1e300000: -10,
1e300000/1e300000: 100,
}
NATIVES1: None
NATIVES2: None
OUTPUT:
{negative infinity: !!float '-1.#INF', not a number: !!float '-1.#IND', sexagesimal: 685230.15000000002,
fixed: 685230.15000000002, canonical: 685230.15000000002, exponential: 685230.15000000002}
NATIVES1: {'exponential': 685230.15000000002, 'negative infinity': -1.#INF, 'sexagesimal': 685230.15000000002, 'not a number': -1.#IND, 'fixed': 685230.15000000002, 'canonical': 685230.15000000002}
NATIVES2: None
OUTPUT:
{!!float '-1.#IND': 100, .inf: 1, !!float '-1.#INF': -10, !!float '1.#INF': 10}
NATIVES1: {-1.#IND: 100, 1.0: 1, -1.#INF: -10, 1.#INF: 10}
NATIVES2: None
bda node: self.yaml_constructors[node.tag](self, node)
File "build/lib\yaml\constructor.py", line 259, in construct_yaml_float
return float(value)
ValueError: invalid literal for float(): 1.#IND
======================================================================
ERROR: testTypes_float_representer_2_3_bug (test_representer.TestRepresenterTypes)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\pyyaml\trunk\tests\test_appliance.py", line 28, in test_method
getattr(self, '_'+method_name)(test, *filenames)
File "C:\pyyaml\trunk\tests\test_representer.py", line 15, in _testTypes
data2 = load(output, Loader=MyLoader)
File "build/lib\yaml\__init__.py", line 61, in load
return loader.get_data()
File "build/lib\yaml\constructor.py", line 41, in get_data
return self.construct_document(self.get_node())
File "build/lib\yaml\constructor.py", line 49, in construct_document
data = self.construct_object(node)
File "build/lib\yaml\constructor.py", line 86, in construct_object
data = constructor(node)
File "build/lib\yaml\constructor.py", line 63, in <lambda>
constructor = lambda node: self.yaml_constructors[node.tag](self, node)
File "build/lib\yaml\constructor.py", line 358, in construct_yaml_map
return self.construct_mapping(node)
File "build/lib\yaml\constructor.py", line 145, in construct_mapping
key = self.construct_object(key_node)
File "build/lib\yaml\constructor.py", line 86, in construct_object
data = constructor(node)
File "build/lib\yaml\constructor.py", line 63, in <lambda>
constructor = lambda node: self.yaml_constructors[node.tag](self, node)
File "build/lib\yaml\constructor.py", line 259, in construct_yaml_float
return float(value)
ValueError: invalid literal for float(): 1.#IND
======================================================================
FAIL: testTypes_construct_float (test_constructor.TestConstructorTypes)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\pyyaml\trunk\tests\test_appliance.py", line 28, in test_method
getattr(self, '_'+method_name)(test, *filenames)
File "C:\pyyaml\trunk\tests\test_constructor.py", line 255, in _testTypes
self.failUnlessEqual(data1, data2)
AssertionError: {'exponential': 685230.15000000002, 'negative infinity': -1.0, 'sexagesimal': 685230.15000000002, 'not a number': 1.0, 'fixed': 685230.15000000002, 'canonical': 685230.15000000002} != {'exponential': 685230.15000000002, 'negative infinity': -1.#INF, 'sexagesimal': 685230.15000000002, 'not a number': -1.#IND, 'fixed': 685230.15000000002, 'canonical': 685230.15000000002}
----------------------------------------------------------------------
Ran 1130 tests in 7.781s
FAILED (failures=1, errors=3)
>Exit code: 1
|
|||
| #9 | fixed | Forcing block style | xi | edemaine@… |
| Description |
Is there an easy way to force the emitter to use block style instead of flow style? I have one particular case in mind where it would be particularly desirable: ordered dictionaries. For example: >>> yaml.load('[hello: world, goodbye: world]')
[{'hello': 'world'}, {'goodbye': 'world'}]
>>> print yaml.dump(_)
- {hello: world}
- {goodbye: world}
In my opinion, the output would look much nicer as - hello: world - goodbye: world Even if you don't agree with this opinion, there should be a way to force block style in all output. I did not see an easy way to do this, even with subclassing. Suggestions? |
|||
