Skip to content

ENH: change flatten to ravel (in internals/pytables) #2921

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def where(self, other, cond, raise_on_error = True, try_cast = False):

# our where function
def func(c,v,o):
if c.flatten().all():
if c.ravel().all():
return v

try:
Expand Down Expand Up @@ -649,7 +649,7 @@ class ObjectBlock(Block):
@property
def is_bool(self):
""" we can be a bool if we have only bool values but are of type object """
return lib.is_bool_array(self.values.flatten())
return lib.is_bool_array(self.values.ravel())

def convert(self, convert_dates = True, convert_numeric = True, copy = True):
""" attempt to coerce any object types to better types
Expand Down Expand Up @@ -751,7 +751,7 @@ def make_block(values, items, ref_items):

# try to infer a datetimeblock
if klass is None and np.prod(values.shape):
flat = values.flatten()
flat = values.ravel()
inferred_type = lib.infer_dtype(flat)
if inferred_type == 'datetime':

Expand Down
8 changes: 4 additions & 4 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1088,7 +1088,7 @@ def set_atom(self, block, existing_col, min_itemsize, nan_rep, **kwargs):

self.values = list(block.items)
dtype = block.dtype.name
inferred_type = lib.infer_dtype(block.values.flatten())
inferred_type = lib.infer_dtype(block.values.ravel())

if inferred_type == 'datetime64':
self.set_atom_datetime64(block)
Expand Down Expand Up @@ -1116,7 +1116,7 @@ def set_atom_string(self, block, existing_col, min_itemsize, nan_rep):
data = block.fillna(nan_rep).values

# itemsize is the maximum length of a string (along any dimension)
itemsize = lib.max_len_string_array(data.flatten())
itemsize = lib.max_len_string_array(data.ravel())

# specified min_itemsize?
if isinstance(min_itemsize, dict):
Expand Down Expand Up @@ -1209,7 +1209,7 @@ def convert(self, values, nan_rep):
# convert nans
if self.kind == 'string':
self.data = lib.array_replace_from_nan_rep(
self.data.flatten(), nan_rep).reshape(self.data.shape)
self.data.ravel(), nan_rep).reshape(self.data.shape)
return self

def get_attr(self):
Expand Down Expand Up @@ -1628,7 +1628,7 @@ def write_array(self, key, value):
if value.dtype.type == np.object_:

# infer the type, warn if we have a non-string type here (for performance)
inferred_type = lib.infer_dtype(value.flatten())
inferred_type = lib.infer_dtype(value.ravel())
if empty_array:
pass
elif inferred_type == 'string':
Expand Down
2 changes: 1 addition & 1 deletion pandas/stats/var.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def _forecast_cov_beta_raw(self, n):

for t in xrange(T + 1):
index = t + p
y = values.take(xrange(index, index - p, -1), axis=0).flatten()
y = values.take(xrange(index, index - p, -1), axis=0).ravel()
trans_Z = np.hstack(([1], y))
trans_Z = trans_Z.reshape(1, len(trans_Z))

Expand Down
14 changes: 14 additions & 0 deletions vb_suite/io_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@
frame_to_csv = Benchmark("df.to_csv('__test__.csv')", setup,
start_date=datetime(2011, 1, 1))

#----------------------------------
setup = common_setup + """
from pandas import concat, Timestamp

df_float = DataFrame(np.random.randn(1000, 30),dtype='float64')
df_int = DataFrame(np.random.randn(1000, 30),dtype='int64')
df_bool = DataFrame(True,index=df_float.index,columns=df_float.columns)
df_object = DataFrame('foo',index=df_float.index,columns=df_float.columns)
df_dt = DataFrame(Timestamp('20010101'),index=df_float.index,columns=df_float.columns)
df = concat([ df_float, df_int, df_bool, df_object, df_dt ], axis=1)
"""
frame_to_csv_mixed = Benchmark("df.to_csv('__test__.csv')", setup,
start_date=datetime(2012, 6, 1))

#----------------------------------------------------------------------
# parse dates, ISO8601 format

Expand Down