Skip to content

Commit

Permalink
first commit with cleaned up code
Browse files Browse the repository at this point in the history
git-svn-id: http://pandas.googlecode.com/svn/trunk@5 d5231056-7de3-11de-ac95-d976489f1ece
  • Loading branch information
wesm committed Aug 5, 2009
1 parent 445114e commit c6b236d
Show file tree
Hide file tree
Showing 36 changed files with 21,658 additions and 0 deletions.
30 changes: 30 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright (c) 2008-2009 AQR Capital Management, LLC
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of the copyright holder nor the names of any
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include TODO LICENSE README
include setup.py setupegg.py
include examples/data/*
recursive-include examples *
Empty file added README
Empty file.
Empty file added TODO
Empty file.
36 changes: 36 additions & 0 deletions pandas/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""
Pandas - a library for panel, time series, or cross-sectional data analysis
===========================================================================
Main data structures (see docstrings for detailed documentation)
--------------------
Index
Represent row or column labels in Series / DataFrame structures
Series / TimeSeries
Represents standard 1-dimensional cross-section (resp. time series)
As an numpy.ndarray subclass, compatible with ufuncs and other NumPy
functions
DataFrame / DataMatrix
Represent collections of Series objects, enable easy management
of multiple time series / cross-sections
DateRange
Index subclass for generating arrays of fixed frequency dates
Subpackages
-----------
core
Implementations of core data structures, basic building blocks. Most of
the user-relevant code is accessible through the top-level namespace
io
Persistence, parsing, and data loading tools
lib
C, Cython, and Fortran extensions for other components
stats
Standard
"""

from pandas.core.api import *
from pandas.io.parsers import parseCSV, parseText, parseExcel
Empty file added pandas/core/__init__.py
Empty file.
12 changes: 12 additions & 0 deletions pandas/core/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import numpy as np

from pandas.core.daterange import DateRange
from pandas.core.datetools import DateOffset
from pandas.core.frame import DataFrame
from pandas.core.index import Index
from pandas.core.matrix import DataMatrix
from pandas.core.series import Series, TimeSeries

import pandas.core.datetools as datetools

from pandas.lib.tseries import isnull, notnull
88 changes: 88 additions & 0 deletions pandas/core/collection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
from __future__ import with_statement

from collections import defaultdict
from pandas.core.mixins import Picklable
from pandas.core.index import Index
from pandas.core.pytools import rands, adjoin, groupby
import cPickle
import os

__all__ = ['PickleContainer']

class PickleContainer(Picklable):
"""
Store collection of objects on disk with this dict-like object.
Parameters
----------
dirPath: string
Directory where to store the objects
lruSize: int
Number of objects to keep in memory (not implemented yet)
"""
def __init__(self, dirPath, lruSize=5):
self.dirPath = dirPath
if not os.path.exists(dirPath):
os.mkdir(dirPath)

self._lruSize = lruSize

self._paths = {}
self._classes = {}
self._lru = {}

def __repr__(self):
output = str(self.__class__) + '\n'
keys, values = zip(*self._classes.iteritems())
output += adjoin(5, map(str, keys), map(str, values))
return output

def __setitem__(self, key, value):
theKey = rands(10)
filePath = self.dirPath + '/' + theKey

self._paths[key] = filePath

if isinstance(value, Picklable):
value.save(filePath)
else:
with open(filePath, 'w') as f:
cPickle.dump(value, f)

self._paths[key] = filePath
self._classes[key] = value.__class__

def __getitem__(self, key):
if key not in self._paths:
raise Exception('Requested key not in this container!')

thePath = self._paths[key]
theClass = self._classes[key]

if issubclass(theClass, Picklable):
obj = theClass.load(thePath)
else:
with open(thePath, 'rb') as f:
obj = cPickle.load(f)

return obj

def __delitem__(self, key):
del self._paths[key]
del self._classes[key]

def __iter__(self):
return iter(self._paths)

def iteritems(self):
for key, path in self._paths.iteritems():
yield key, self[key]

def keys(self):
return self._paths.keys()

def values(self):
result = []
for key in self._paths:
result.append(self[key])
return result
Loading

0 comments on commit c6b236d

Please sign in to comment.