예제 #1
0
파일: test_io.py 프로젝트: mabudz/pyam
def test_init_df_with_na_unit(test_pd_df, tmpdir):
    # missing values in the unit column are replaced by an empty string
    test_pd_df.loc[1, "unit"] = np.nan
    df = IamDataFrame(test_pd_df)
    assert df.unit == ["", "EJ/yr"]

    # writing to file and importing as pandas returns `nan`, not empty string
    file = tmpdir / "na_unit.csv"
    df.to_csv(file)
    df_csv = pd.read_csv(file)
    assert np.isnan(df_csv.loc[1, "Unit"])
    IamDataFrame(file)  # reading from file as IamDataFrame works

    file = tmpdir / "na_unit.xlsx"
    df.to_excel(file)
    df_excel = pd.read_excel(file, engine="openpyxl")
    assert np.isnan(df_excel.loc[1, "Unit"])
    IamDataFrame(file)  # reading from file as IamDataFrame works
예제 #2
0
파일: test_io.py 프로젝트: schipfer/pyam
def test_init_df_with_na_unit(test_pd_df, tmpdir):
    # missing values in the unit column are replaced by an empty string
    test_pd_df.loc[1, 'unit'] = np.nan
    df = IamDataFrame(test_pd_df)
    assert df.unit == ['', 'EJ/yr']

    # writing to file and importing as pandas returns `nan`, not empty string
    file = tmpdir / 'na_unit.csv'
    df.to_csv(file)
    df_csv = pd.read_csv(file)
    assert np.isnan(df_csv.loc[1, 'Unit'])
    IamDataFrame(file)  # reading from file as IamDataFrame works

    file = tmpdir / 'na_unit.xlsx'
    df.to_excel(file)
    df_excel = pd.read_excel(file)
    assert np.isnan(df_excel.loc[1, 'Unit'])
    IamDataFrame(file)  # reading from file as IamDataFrame works