Skip to content

TypeError: object of type 'NoneType' has no len() with MySQL empty columns #3523

Closed
@randyzwitch

Description

@randyzwitch

pandas '0.11.0'
mysql.connector '1.0.9'

Import statements and options

import mysql.connector
from mysql.connector import errorcode
import pandas.io.sql as sql
import pandas as pd
from pandas import DataFrame

Error

Running this code against MySQL (view includes several completely blank columns):

#Queries for CCI since Nov 2012
queries = sql.read_frame("select * from vw_queries_lj where query_account_id='34' and from_unixtime(query_created, '%Y-%m-%d') >= '2012-11-01' limit 100;", con)

Causes this error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-17-78e88f1ac26a> in <module>()
      1 #Queries for CCI since Nov 2012
----> 2 queries = sql.read_frame("select * from vw_queries_lj where query_account_id='34' and from_unixtime(query_created, '%Y-%m-%d') >= '2012-11-01' limit 100;", con)
      3 

/Users/randyzwitch/anaconda/lib/python2.7/site-packages/pandas/io/sql.pyc in read_frame(sql, con, index_col, coerce_float, params)
    160 
    161     result = DataFrame.from_records(rows, columns=columns,
--> 162                                     coerce_float=coerce_float)
    163 
    164     if index_col is not None:

/Users/randyzwitch/anaconda/lib/python2.7/site-packages/pandas/core/frame.pyc in from_records(cls, data, index, exclude, columns, coerce_float, nrows)
   1070         else:
   1071             arrays, arr_columns = _to_arrays(data, columns,
-> 1072                                              coerce_float=coerce_float)
   1073 
   1074             arr_columns = _ensure_index(arr_columns)

/Users/randyzwitch/anaconda/lib/python2.7/site-packages/pandas/core/frame.pyc in _to_arrays(data, columns, coerce_float, dtype)
   5449         return arrays, columns
   5450 
-> 5451     if len(data) == 0:
   5452         return [], []  # columns if columns is not None else []
   5453     if isinstance(data[0], (list, tuple)):

TypeError: object of type 'NoneType' has no len()

No error

Running query on primary key (i.e. no blanks) returns a proper data frrame

#Queries for CCI since Nov 2012
queries = sql.read_frame("select token from vw_queries_lj where query_account_id='34' and from_unixtime(query_created, '%Y-%m-%d') >= '2012-11-01' limit 100;", con)

Expectation

My expected behavior would be that pandas would be able to handle blank columns as character or float, not as NoneType

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions