windng
Check-in [da152f922f]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Make it work with pandas 0.17.1
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:da152f922f92f55747847513d7d9b0276c97c57f
User & Date: goyo 2015-11-24 08:09:06
Context
2015-11-24
08:26
Make setup.py work with pip in python2. check-in: 9b2e9b9e05 user: goyo tags: trunk
08:09
Make it work with pandas 0.17.1 check-in: da152f922f user: goyo tags: trunk
2015-10-28
23:48
Improvements to turbulence(). check-in: b9977fb29f user: goyo tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to test/test_io.py.

   437    437   19910201 0200    4.8    350   11.8    1007.2
   438    438   19910201 0300    6.0    352   11.9    1007.5
   439    439   19910201 0400    5.3    352   11.0    1007.9
   440    440   """)
   441    441           result = wio.read_vortex(sample, prefix='X')
   442    442   
   443    443           tuples = [
   444         -            ('WS', 'M(m/s)', 80, 'avg'),
   445         -            ('WD', 'D(deg)', 80, 'avg'),
   446         -            ('T', 'T(C)', 80, 'avg'),
   447         -            ('P', 'PRE(hPa)', 80, 'avg')
          444  +            ('WS', 'M(m/s)', 80., 'avg'),
          445  +            ('WD', 'D(deg)', 80., 'avg'),
          446  +            ('T', 'T(C)', 80., 'avg'),
          447  +            ('P', 'PRE(hPa)', 80., 'avg')
   448    448           ]
   449    449           names = ['kind', 'name', 'height', 'signal']
   450    450           expected_columns = pd.MultiIndex.from_tuples(tuples, names=names)
   451    451           expected_index = pd.date_range('1991-02-01', periods=5, freq='H',
   452    452               name='YYYYMMDD_HHMM')
   453    453           expected_data = np.array([
   454    454               [6.4, 344, 13.7, 1007.3],
................................................................................
   663    663   01/08/2010 00:10\t3.1\t3.7	101
   664    664   01/08/2010 00:20\t2.5\t2.8\t
   665    665   """
   666    666           )
   667    667           result = wio.read_aire(sample, skip_mast_name=True)
   668    668           expected_columns = pd.MultiIndex.from_tuples(
   669    669               [
   670         -                (u'WS', u'78.0_SW_2.5_1_10', 78, u'avg'),
   671         -                (u'WS', u'78.0_SW_2.5_1_10', 78, u'max'),
          670  +                (u'WS', u'78.0_SW_2.5_1_10', 78., u'avg'),
          671  +                (u'WS', u'78.0_SW_2.5_1_10', 78., u'max'),
   672    672                   (u'', u'Etiqueta', 0, u'lbl')
   673    673               ],
   674    674               names=['kind', 'name', 'height', 'signal']
   675    675           )
   676    676           expected_index = pd.date_range('2010-07-31 23:40',
   677    677               periods=5, freq='10T')
   678    678           expected_values = np.array([

Changes to test/test_turbines.py.

   147    147       def test_from_json(self):
   148    148           text = r'{"name": "A name", "description": "A description", "rated_power": 10, "power": "{\"2.0\":{\"3\":1.0,\"4\":2.0,\"5\":4.0},\"2.2\":{\"3\":1.2,\"4\":2.2,\"5\":4.2},\"2.4\":{\"3\":1.4,\"4\":2.4,\"5\":4.4}}"}'
   149    149           result = turbines.TurbineType.from_json(text)
   150    150           power = pd.DataFrame(
   151    151               [[1, 1.2, 1.4],
   152    152                [2, 2.2, 2.4],
   153    153                [4, 4.2, 4.4]],
   154         -            index=[3, 4, 5], columns=[2, 2.2, 2.4]
          154  +            index=[3., 4., 5.], columns=[2, 2.2, 2.4]
   155    155           )
   156    156           t = turbines.TurbineType(name='A name', description='A description',
   157    157               power=power, rated_power=10)
   158    158           self.assertEqual(result.name, t.name)
   159    159           self.assertEqual(result.description, t.description)
   160    160           self.assertEqual(result._rated_power, t._rated_power)
   161    161           pdt.assert_frame_equal(result.power, t.power)

Changes to test/test_wind.py.

  1883   1883               348.75
  1884   1884           ]
  1885   1885   
  1886   1886           speed = abs(np.sin(np.arange(1000)) + 0.2) * 10
  1887   1887           dir = (np.cos(np.arange(1000))**2) * 359
  1888   1888   
  1889   1889           ftable = wind.freq_table(speed, dir, dataframe=True)
  1890         -        expected = pd.DataFrame(expected_freqs, index=range(12),
         1890  +        expected = pd.DataFrame(expected_freqs, index=np.arange(12.),
  1891   1891               columns=range(16))
  1892   1892           pdt.assert_frame_equal(ftable, expected)
  1893   1893   
  1894   1894           freqs, sbins, dbins = wind.freq_table(speed, dir, dataframe=False)
  1895   1895           np.testing.assert_array_almost_equal(freqs, expected_freqs)
  1896   1896           np.testing.assert_array_equal(sbins, range(13))
  1897   1897           np.testing.assert_array_equal(dbins, expected_dbins)
................................................................................
  1924   1924           # Add a lot of nans.
  1925   1925           speed = pd.Series(speed, index=np.arange(2000, step=2))
  1926   1926           speed = speed.reindex(np.arange(2000))
  1927   1927           dir = pd.Series(dir, index=np.arange(2000, step=2))
  1928   1928           dir = dir.reindex(np.arange(2000))
  1929   1929   
  1930   1930           ftable = wind.freq_table(speed, dir, dataframe=True)
  1931         -        expected = pd.DataFrame(expected_freqs, index=range(12),
         1931  +        expected = pd.DataFrame(expected_freqs, index=np.arange(12.),
  1932   1932               columns=range(16))
  1933   1933           pdt.assert_frame_equal(ftable, expected)
  1934   1934   
  1935   1935           freqs, sbins, dbins = wind.freq_table(speed, dir, dataframe=False)
  1936   1936           np.testing.assert_array_almost_equal(freqs, expected_freqs)
  1937   1937           np.testing.assert_array_equal(sbins, range(13))
  1938   1938           np.testing.assert_array_equal(dbins, expected_dbins)
................................................................................
  1959   1959               348.75
  1960   1960           ]
  1961   1961   
  1962   1962           speed = list(abs(np.sin(np.arange(1000)) + 0.2) * 10)
  1963   1963           dir = list((np.cos(np.arange(1000))**2) * 359)
  1964   1964   
  1965   1965           ftable = wind.freq_table(speed, dir, dataframe=True)
  1966         -        expected = pd.DataFrame(expected_freqs, index=range(12),
         1966  +        expected = pd.DataFrame(expected_freqs, index=np.arange(12.),
  1967   1967               columns=range(16))
  1968   1968           pdt.assert_frame_equal(ftable, expected)
  1969   1969   
  1970   1970           freqs, sbins, dbins = wind.freq_table(speed, dir, dataframe=False)
  1971   1971           np.testing.assert_array_almost_equal(freqs, expected_freqs)
  1972   1972           np.testing.assert_array_equal(sbins, range(13))
  1973   1973           np.testing.assert_array_equal(dbins, expected_dbins)

Changes to windng/io.py.

    31     31   from datetime import datetime
    32     32   import io
    33     33   import warnings
    34     34   
    35     35   import numpy as np
    36     36   import pandas as pd
    37     37   from pandas.io.common import get_filepath_or_buffer  # filepath_or_buffer, encoding
    38         -from pandas.core.common import _get_handle  # path, mode, encoding=None, compression=None
    39     38   
    40     39   import windng.wind as wind
    41     40   
    42     41   
    43     42   def _date_parser(date_format):
    44     43       strptime = datetime.strptime
    45     44       def theparser(*s):
................................................................................
   330    329           'u2': lambda x: format(x, '8.2f'),
   331    330           'std_speed': lambda x: format(x, '6.2f'),
   332    331       }
   333    332   
   334    333       if hasattr(path_or_buf, 'write'):
   335    334           buf = path_or_buf
   336    335       else:
   337         -        buf = _get_handle(path_or_buf, 'w',)
          336  +        buf = open(path_or_buf, 'w')
   338    337   
   339    338   
   340    339       # XXX This does not work due to a bug in pandas (ignores col_space).
   341    340       #~ dframe.to_string(buf, header=False, index=False,
   342    341           #~ formatters=formatters, col_space=0)
   343    342   
   344    343       # Temporary workaround.
................................................................................
   377    376           ('TI', getcol(ticol, 'TI'))
   378    377       ])
   379    378       dframe.index = index
   380    379       dframe = dframe.dropna(how='any', subset=['Speed', 'Direction'])
   381    380       if hasattr(path_or_buf, 'write'):
   382    381           buf = path_or_buf
   383    382       else:
   384         -        buf = _get_handle(path_or_buf, 'w',)
          383  +        buf = open(path_or_buf, 'w')
   385    384   
   386    385       buf.write('MM,{}\n'.format(mm))
   387    386       buf.write('{},{},{}\n'.format(lon, lat, hubheight))
   388    387       buf.write('{},{},{}\n'.format(uncertainty, shortname, longname))
   389    388       buf.write('Year,Month,Day,Hour,Minute,WS,DIR,Temp,Density,TI[%]\n')
   390    389   
   391    390       # XXX This does not work due to a bug in pandas (ignores col_space).