Example #1
0
    def test_convert_sql_column_bools(self):
        arr = np.array([True, False, True, False], dtype='O')
        result = lib.convert_sql_column(arr)
        expected = np.array([True, False, True, False], dtype=bool)
        assert_same_values_and_dtype(result, expected)

        arr = np.array([True, False, None, False], dtype='O')
        result = lib.convert_sql_column(arr)
        expected = np.array([True, False, np.nan, False], dtype=object)
        assert_same_values_and_dtype(result, expected)
Example #2
0
    def test_convert_sql_column_longs(self):
        arr = np.array([1L, 2L, 3L, 4L], dtype="O")
        result = lib.convert_sql_column(arr)
        expected = np.array([1, 2, 3, 4], dtype="i8")
        assert_same_values_and_dtype(result, expected)

        arr = np.array([1L, 2L, 3L, None, 4L], dtype="O")
        result = lib.convert_sql_column(arr)
        expected = np.array([1, 2, 3, np.nan, 4], dtype="f8")
        assert_same_values_and_dtype(result, expected)
Example #3
0
    def test_convert_sql_column_longs(self):
        arr = np.array([1L, 2L, 3L, 4L], dtype='O')
        result = lib.convert_sql_column(arr)
        expected = np.array([1, 2, 3, 4], dtype='i8')
        assert_same_values_and_dtype(result, expected)

        arr = np.array([1L, 2L, 3L, None, 4L], dtype='O')
        result = lib.convert_sql_column(arr)
        expected = np.array([1, 2, 3, np.nan, 4], dtype='f8')
        assert_same_values_and_dtype(result, expected)
Example #4
0
    def test_convert_sql_column_bools(self):
        arr = np.array([True, False, True, False], dtype="O")
        result = lib.convert_sql_column(arr)
        expected = np.array([True, False, True, False], dtype=bool)
        assert_same_values_and_dtype(result, expected)

        arr = np.array([True, False, None, False], dtype="O")
        result = lib.convert_sql_column(arr)
        expected = np.array([True, False, np.nan, False], dtype=object)
        assert_same_values_and_dtype(result, expected)
Example #5
0
    def test_convert_sql_column_ints(self):
        arr = np.array([1, 2, 3, 4], dtype='O')
        arr2 = np.array([1, 2, 3, 4], dtype='i4').astype('O')
        result = lib.convert_sql_column(arr)
        result2 = lib.convert_sql_column(arr2)
        expected = np.array([1, 2, 3, 4], dtype='i8')
        assert_same_values_and_dtype(result, expected)
        assert_same_values_and_dtype(result2, expected)

        arr = np.array([1, 2, 3, None, 4], dtype='O')
        result = lib.convert_sql_column(arr)
        expected = np.array([1, 2, 3, np.nan, 4], dtype='f8')
        assert_same_values_and_dtype(result, expected)
Example #6
0
    def test_convert_sql_column_ints(self):
        arr = np.array([1, 2, 3, 4], dtype="O")
        arr2 = np.array([1, 2, 3, 4], dtype="i4").astype("O")
        result = lib.convert_sql_column(arr)
        result2 = lib.convert_sql_column(arr2)
        expected = np.array([1, 2, 3, 4], dtype="i8")
        assert_same_values_and_dtype(result, expected)
        assert_same_values_and_dtype(result2, expected)

        arr = np.array([1, 2, 3, None, 4], dtype="O")
        result = lib.convert_sql_column(arr)
        expected = np.array([1, 2, 3, np.nan, 4], dtype="f8")
        assert_same_values_and_dtype(result, expected)
Example #7
0
    def test_convert_sql_column_ints(self):
        arr = np.array([1, 2, 3, 4], dtype='O')
        arr2 = np.array([1, 2, 3, 4], dtype='i4').astype('O')
        result = lib.convert_sql_column(arr)
        result2 = lib.convert_sql_column(arr2)
        expected = np.array([1, 2, 3, 4], dtype='i8')
        assert_same_values_and_dtype(result, expected)
        assert_same_values_and_dtype(result2, expected)

        arr = np.array([1, 2, 3, None, 4], dtype='O')
        result = lib.convert_sql_column(arr)
        expected = np.array([1, 2, 3, np.nan, 4], dtype='f8')
        assert_same_values_and_dtype(result, expected)
Example #8
0
    def test_convert_sql_column_decimals(self):
        from decimal import Decimal

        arr = np.array([Decimal("1.5"), None, Decimal("3"), Decimal("4.2")])
        result = lib.convert_sql_column(arr)
        expected = np.array([1.5, np.nan, 3, 4.2], dtype="f8")
        assert_same_values_and_dtype(result, expected)
Example #9
0
def list_to_dataframe(rows, names):
    import pandas._tseries as lib
    from pandas import DataFrame

    if isinstance(rows, tuple):
        rows = list(rows)

    columns = dict(zip(names, lib.to_object_array_tuples(rows).T))

    for k, v in columns.iteritems():
        columns[k] = lib.convert_sql_column(v)

    return DataFrame(columns, columns=names)
Example #10
0
def list_to_dataframe(rows, names):
    """
    Turns a rows of data into a dataframe and gives them the column names
    specified

    :params rows: the data you want to put in the dataframe
    :params names: the column names for the dataframe
    """
    from pandas import DataFrame
    try:
        import pandas._tseries as lib
    except ImportError:
        import pandas.lib as lib

    if isinstance(rows, tuple):
        rows = list(rows)

    columns = dict(zip(names, lib.to_object_array_tuples(rows).T))

    for k, v in columns.iteritems():
        columns[k] = lib.convert_sql_column(v)

    return DataFrame(columns, columns=names)
Example #11
0
 def test_convert_sql_column_strings(self):
     arr = np.array(['1.5', None, '3', '4.2'], dtype=object)
     result = lib.convert_sql_column(arr)
     expected = np.array(['1.5', np.nan, '3', '4.2'], dtype=object)
     assert_same_values_and_dtype(result, expected)
Example #12
0
 def test_convert_sql_column_floats(self):
     arr = np.array([1.5, None, 3, 4.2], dtype=object)
     result = lib.convert_sql_column(arr)
     expected = np.array([1.5, np.nan, 3, 4.2], dtype='f8')
     assert_same_values_and_dtype(result, expected)
Example #13
0
 def test_convert_sql_column_strings(self):
     arr = np.array(['1.5', None, '3', '4.2'], dtype=object)
     result = lib.convert_sql_column(arr)
     expected = np.array(['1.5', np.nan, '3', '4.2'], dtype=object)
     assert_same_values_and_dtype(result, expected)
Example #14
0
 def test_convert_sql_column_unicode(self):
     arr = np.array([u'1.5', None, u'3', u'4.2'], dtype=object)
     result = lib.convert_sql_column(arr)
     expected = np.array([u'1.5', np.nan, u'3', u'4.2'], dtype=object)
     assert_same_values_and_dtype(result, expected)
Example #15
0
 def test_convert_sql_column_unicode(self):
     arr = np.array([u"1.5", None, u"3", u"4.2"], dtype=object)
     result = lib.convert_sql_column(arr)
     expected = np.array([u"1.5", np.nan, u"3", u"4.2"], dtype=object)
     assert_same_values_and_dtype(result, expected)
Example #16
0
 def test_convert_sql_column_strings(self):
     arr = np.array(["1.5", None, "3", "4.2"], dtype=object)
     result = lib.convert_sql_column(arr)
     expected = np.array(["1.5", np.nan, "3", "4.2"], dtype=object)
     assert_same_values_and_dtype(result, expected)
Example #17
0
 def test_convert_sql_column_floats(self):
     arr = np.array([1.5, None, 3, 4.2], dtype=object)
     result = lib.convert_sql_column(arr)
     expected = np.array([1.5, np.nan, 3, 4.2], dtype="f8")
     assert_same_values_and_dtype(result, expected)
Example #18
0
 def test_convert_sql_column_decimals(self):
     from decimal import Decimal
     arr = np.array([Decimal('1.5'), None, Decimal('3'), Decimal('4.2')])
     result = lib.convert_sql_column(arr)
     expected = np.array([1.5, np.nan, 3, 4.2], dtype='f8')
     assert_same_values_and_dtype(result, expected)
Example #19
0
 def test_convert_sql_column_unicode(self):
     arr = np.array([u'1.5', None, u'3', u'4.2'], dtype=object)
     result = lib.convert_sql_column(arr)
     expected = np.array([u'1.5', np.nan, u'3', u'4.2'], dtype=object)
     assert_same_values_and_dtype(result, expected)
Example #20
0
 def test_convert_sql_column_decimals(self):
     from decimal import Decimal
     arr = np.array([Decimal('1.5'), None, Decimal('3'), Decimal('4.2')])
     result = lib.convert_sql_column(arr)
     expected = np.array([1.5, np.nan, 3, 4.2], dtype='f8')
     assert_same_values_and_dtype(result, expected)