Ejemplo n.º 1
0
def test_bug35():
    "Bug 35"
    txt_array = DataArray(['a','b'], axes=['dummy'])
    #calling datarray_to_string on string arrays used to fail
    print_grid.datarray_to_string(txt_array)
    #because get_formatter returned the class not an instance
    assert isinstance(print_grid.get_formatter(txt_array),
                      print_grid.StrFormatter)
Ejemplo n.º 2
0
def test_bug35():
    "Bug 35"
    txt_array = DataArray(['a', 'b'], axes=['dummy'])
    #calling datarray_to_string on string arrays used to fail
    print_grid.datarray_to_string(txt_array)
    #because get_formatter returned the class not an instance
    assert isinstance(print_grid.get_formatter(txt_array),
                      print_grid.StrFormatter)
Ejemplo n.º 3
0
def test_bug34():
    "Bug 34: datetime.date ticks not handled by datarray_to_string"
    from datarray.print_grid import datarray_to_string
    from datetime import date as D
    A = DataArray([[1,2],[3,4]], [('row', ('a', D(2010,1,1))),('col', 'cd')])
    exp_out = """row       col                
--------- -------------------
          c         d        
a                 1         2
2010-01-0         3         4"""
    nt.assert_equal(datarray_to_string(A), exp_out)
    # Output for unsigned integers
    B = A.astype(np.uint32)
    nt.assert_equal(datarray_to_string(B), exp_out)
Ejemplo n.º 4
0
def test_bug34():
    "Bug 34: datetime.date ticks not handled by datarray_to_string"
    from datarray.print_grid import datarray_to_string
    from datetime import date as D
    A = DataArray([[1,2],[3,4]], [('row', ('a', D(2010,1,1))),('col', 'cd')])
    nt.assert_equal(datarray_to_string(A), """row       col                
--------- -------------------
          c         d        
a                 1         2
2010-01-0         3         4""")
Ejemplo n.º 5
0
def test_bug34():
    "Bug 34: datetime.date ticks not handled by datarray_to_string"
    from datarray.print_grid import datarray_to_string
    from datetime import date as D
    A = DataArray([[1, 2], [3, 4]], [('row', ('a', D(2010, 1, 1))),
                                     ('col', 'cd')])
    nt.assert_equal(
        datarray_to_string(A), """row       col                
--------- -------------------
          c         d        
a                 1         2
2010-01-0         3         4""")
Ejemplo n.º 6
0
def test_1d_datarray_to_string():
    grid_string = """
country                                
---------------------------------------
Netherla  Uruguay   Germany   Spain    
 0.        0.714286  1.428571  2.142857
    """.strip()

    test_array = np.arange(20).reshape((4, 5)) / 7.0
    row_spec = "country", ["Netherlands", "Uruguay", "Germany", "Spain"]
    col_spec = "year", map(str, [1994, 1998, 2002, 2006, 2010])

    d_arr = DataArray(test_array, [row_spec, col_spec])
    assert datarray_to_string(d_arr.axes.year["1994"]) == grid_string
Ejemplo n.º 7
0
def test_1d_datarray_to_string():
    grid_string = """
country                                
---------------------------------------
Netherla  Uruguay   Germany   Spain    
 0.        0.714286  1.428571  2.142857
    """.strip()
    
    test_array = np.arange(20).reshape((4, 5)) / 7.0
    row_spec = 'country', ['Netherlands', 'Uruguay', 'Germany', 'Spain']
    col_spec = 'year', list(map(str, [1994, 1998, 2002, 2006, 2010]))

    d_arr = DataArray(test_array, [row_spec, col_spec])
    assert datarray_to_string(d_arr.axes.year['1994']) == grid_string
Ejemplo n.º 8
0
def test_1d_datarray_to_string():
    grid_string = """
country                                
---------------------------------------
Netherla  Uruguay   Germany   Spain    
 0.        0.714286  1.428571  2.142857
    """.strip()

    test_array = np.arange(20).reshape((4, 5)) / 7.0
    row_spec = 'country', ['Netherlands', 'Uruguay', 'Germany', 'Spain']
    col_spec = 'year', list(map(str, [1994, 1998, 2002, 2006, 2010]))

    d_arr = DataArray(test_array, [row_spec, col_spec])
    assert datarray_to_string(d_arr.axes.year['1994']) == grid_string
Ejemplo n.º 9
0
def test_2d_datarray_to_string():
    grid_string = """
country   year                                             
--------- -------------------------------------------------
          1994      1998      2002      2006      2010     
Netherlan  0.        0.142857  0.285714  0.428571  0.571429
Uruguay    0.714286  0.857143  1.        1.142857  1.285714
Germany    1.428571  1.571429  1.714286  1.857143  2.      
Spain      2.142857  2.285714  2.428571  2.571429  2.714286
    """.strip()

    test_array = np.arange(20).reshape((4, 5)) / 7.0
    row_spec = "country", ["Netherlands", "Uruguay", "Germany", "Spain"]
    col_spec = "year", map(str, [1994, 1998, 2002, 2006, 2010])

    d_arr = DataArray(test_array, [row_spec, col_spec])
    assert datarray_to_string(d_arr) == grid_string
Ejemplo n.º 10
0
def test_2d_datarray_to_string():
    grid_string = """
country   year                                             
--------- -------------------------------------------------
          1994      1998      2002      2006      2010     
Netherlan  0.        0.142857  0.285714  0.428571  0.571429
Uruguay    0.714286  0.857143  1.        1.142857  1.285714
Germany    1.428571  1.571429  1.714286  1.857143  2.      
Spain      2.142857  2.285714  2.428571  2.571429  2.714286
    """.strip()

    test_array = np.arange(20).reshape((4, 5)) / 7.0
    row_spec = 'country', ['Netherlands', 'Uruguay', 'Germany', 'Spain']
    col_spec = 'year', list(map(str, [1994, 1998, 2002, 2006, 2010]))

    d_arr = DataArray(test_array, [row_spec, col_spec])
    assert datarray_to_string(d_arr) == grid_string