Example #1
0
def h2oset_timezone():
    """
    Python API test: h2o.set_timezone(value)
    Deprecated, set h2o.cluster().timezone instead.

    Copy from pyunit_get_set_list_timezones.py
    """
    try:
        origTZ = h2o.get_timezone()
        print("Original timezone: {0}".format(origTZ))

        timezones = h2o.list_timezones()
        # don't use the first one..it's a header for the table
        print("timezones[0]:", timezones[0])
        zone = timezones[random.randint(1, timezones.nrow - 1),
                         0].split(" ")[1].split(",")[0]
        print("Setting the timezone: {0}".format(zone))
        h2o.set_timezone(zone)

        newTZ = h2o.get_timezone()
        assert newTZ == zone, "Expected new timezone to be {0}, but got {01}".format(
            zone, newTZ)

        print("Setting the timezone back to original: {0}".format(origTZ))
        h2o.set_timezone(origTZ)
    except Exception as e:
        assert False, "h2o.set_timezone() command is not working."
def get_set_list_timezones(ip,port):
    # Connect to h2o
    h2o.init(ip,port)

    origTZ = h2o.get_timezone()
    print "Original timezone: {0}".format(origTZ)

    timezones = h2o.list_timezones()
    zone = timezones[random.randint(0,timezones.nrow()-1),0].split(" ")[1].split(",")[0]
    print "Setting the timezone: {0}".format(zone)
    h2o.set_timezone(zone)

    newTZ = h2o.get_timezone()
    assert newTZ == zone, "Expected new timezone to be {0}, but got {01}".format(zone, newTZ)

    print "Setting the timezone back to original: {0}".format(origTZ)
    h2o.set_timezone(origTZ)
def get_set_list_timezones():
    
    

    origTZ = h2o.get_timezone()
    print "Original timezone: {0}".format(origTZ)

    timezones = h2o.list_timezones()
    # don't use the first one..it's a header for the table
    print "timezones[0]:", timezones[0]
    zone = timezones[random.randint(1,timezones.nrow-1),0].split(" ")[1].split(",")[0]
    print "Setting the timezone: {0}".format(zone)
    h2o.set_timezone(zone)

    newTZ = h2o.get_timezone()
    assert newTZ == zone, "Expected new timezone to be {0}, but got {01}".format(zone, newTZ)

    print "Setting the timezone back to original: {0}".format(origTZ)
    h2o.set_timezone(origTZ)
def get_set_list_timezones():

    origTZ = h2o.get_timezone()
    print "Original timezone: {0}".format(origTZ)

    timezones = h2o.list_timezones()
    # don't use the first one..it's a header for the table
    print "timezones[0]:", timezones[0]
    zone = timezones[random.randint(1, timezones.nrow - 1),
                     0].split(" ")[1].split(",")[0]
    print "Setting the timezone: {0}".format(zone)
    h2o.set_timezone(zone)

    newTZ = h2o.get_timezone()
    assert newTZ == zone, "Expected new timezone to be {0}, but got {01}".format(
        zone, newTZ)

    print "Setting the timezone back to original: {0}".format(origTZ)
    h2o.set_timezone(origTZ)
def h2oset_timezone():
    """
    Python API test: h2o.set_timezone(value)
    Deprecated, set h2o.cluster().timezone instead.

    Copy from pyunit_get_set_list_timezones.py
    """
    origTZ = h2o.get_timezone()
    print("Original timezone: {0}".format(origTZ))

    timezones = h2o.list_timezones()
    # don't use the first one..it's a header for the table
    print("timezones[0]:", timezones[0])
    zone = timezones[random.randint(1,timezones.nrow-1),0].split(" ")[1].split(",")[0]
    print("Setting the timezone: {0}".format(zone))
    h2o.set_timezone(zone)

    newTZ = h2o.get_timezone()
    assert newTZ == zone, "Expected new timezone to be {0}, but got {01}".format(zone, newTZ)

    print("Setting the timezone back to original: {0}".format(origTZ))
    h2o.set_timezone(origTZ)
Example #6
0
# Transform census table
# Remove all spaces from column names (causing problems in Spark SQL)
col_names = map(lambda s: s.strip().replace(' ', '_').replace('+', '_'), f_census.col_names)

# Update column names in the table
# f_weather.names = col_names
f_census.names = col_names


# Transform crimes table
# Drop useless columns
f_crimes = f_crimes[2:]

# Set time zone to UTC for date manipulation
h2o.set_timezone("Etc/UTC")

# Replace ' ' by '_' in column names
col_names = map(lambda s: s.replace(' ', '_'), f_crimes.col_names)
f_crimes.names = col_names
refine_date_col(f_crimes, "Date", "%m/%d/%Y %I:%M:%S %p")
f_crimes = f_crimes.drop("Date")

# Expose H2O frames as Spark DataFrame

df_weather = h2oContext.as_spark_frame(f_weather)
df_census = h2oContext.as_spark_frame(f_census)
df_crimes = h2oContext.as_spark_frame(f_crimes)

# Use Spark SQL to join datasets
# Transform census table
# Remove all spaces from column names (causing problems in Spark SQL)
col_names = map(lambda s: s.strip().replace(' ', '_').replace('+', '_'), f_census.col_names)

# Update column names in the table
# f_weather.names = col_names
f_census.names = col_names


# Transform crimes table
# Drop useless columns
f_crimes = f_crimes[2:]

# Set time zone to UTC for date manipulation
h2o.set_timezone("Etc/UTC")

# Replace ' ' by '_' in column names
col_names = map(lambda s: s.replace(' ', '_'), f_crimes.col_names)
f_crimes.names = col_names
refine_date_col(f_crimes, "Date", "%m/%d/%Y %I:%M:%S %p")
f_crimes = f_crimes.drop("Date")

# Expose H2O frames as Spark DataFrame

df_weather = h2oContext.as_spark_frame(f_weather)
df_census = h2oContext.as_spark_frame(f_census)
df_crimes = h2oContext.as_spark_frame(f_crimes)

# Use Spark SQL to join datasets