<!-- Content Here -->

Where content meets technology

Dec 10, 2014

Nan, you are not a number

Here is a little programming oddity that we ran across yesterday.

onDemand has a number of downloadable Excel reports. To generate a useful Excel file, it is important to tell the Excel library what data type to make each cell. To facilitate this, we had a little utility function called is_float:

def is_float(data):

    try:
        float(data)
        return True
    except Exception:
        return False

That seemed reasonable enough and it worked fine for quite some time. But then we had this customer named Nan (thanks for the business Nan!). The problem with the name Nan is that float('Nan') doesn't return a ValueError like float('Bob'). float('Nan') successfully returns a float object with a value of 'nan.' The reason for this is that Nan, in addition to a being fairly common name (I went to school with a girl named Nan), is Python shorthand for a "Not a Number." Python's float function interpreted the input 'Nan' as an attempt to create a float object with a value of 'nan'. This caused our logic to try to tell the Excel library that 'Nan' was a number and that created an error. Incidentally, we would have had the same problem with someone named "Inf," which is Python shorthand for infinity.

In case anyone is curious, the fix for this was quite simple:

def is_float(data):

    try:
        int(float(data))
        return True
    except Exception:
        return False

The int function doesn't try to be as clever. It rejects cheeky floats like nan and inf. You learn something new every day!

Sep 10, 2009

Snow Leopard Issues

For some reason, I upgraded to Snow Leopard at my first opportunity. To tell the truth, the end-user improvements are pretty modest and it is difficult to perceive Snow Leopard's slight speed improvements. That is not to say that the upgrade did not have impact. Some software that I regularly use stopped working. I am all up and working now and here is now.


































Problem Solution
Oxygen 9.3 stopped working I upgraded to Oxygen 10.3 for $147
My macport MySQL, Apache, PHP setup broke I tried to do port upgrade of MySQL and PHP and it failed. Compiling my own PHP didn't work either. I wound up installing the MySQL package from the MySQL site and using the Apache and PHP (5.3) that comes with Snow Leopard.
My eZ Publish development environment broke This was because I upgraded to PHP 5.3. This was easily fixed by re-installing eZ Publish because eZ Publish is compatible with PHP 5.3
My Drupal development environment broke Drupal is not compatible with PHP 5.3. Until it is, I am running it on MAMP.
Python MySQL did not easy_install for Python 2.6 This is the problem that I struggled most with. I followed the instructions here. The compile and build worked but I could not import the library. I finally solved the problem by re-installing the 32 bit version of MySQL, setting Python to run in 32 bit, and following these simple instructions.
1Password 2.x is incompatible with Snow Leopard I pre-purchased version 3 and enrolled in the 3.0 beta program. The UI looks really slick and I am happy that I upgraded.
Cornerstone is incompatible with Snow Leopard I am waiting for the next release of Cornerstone (due this month) that will be Snow Leopard compatible and also support Subversion 1.6.

Looking back, it would have made more sense to wait on the upgrade and see what other people on the mailing lists said about their experiences. But, since I figure I would share what I learned.