Skip to content

Wrong repo... #1

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

Closed
wants to merge 2 commits into from
Closed
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: 2 additions & 4 deletions pandas/core/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,6 @@ def __init__(self, obj, path_or_buf=None, sep=",", na_rep='', float_format=None,
self.blocks = self.obj._data.blocks
ncols = sum(len(b.items) for b in self.blocks)
self.data = [None] * ncols
self.column_map = self.obj._data.get_items_map(use_cached=False)

if chunksize is None:
chunksize = (100000 / (len(self.cols) or 1)) or 1
Expand Down Expand Up @@ -1307,10 +1306,9 @@ def _save_chunk(self, start_i, end_i):
float_format=self.float_format,
date_format=self.date_format)

for i, item in enumerate(b.items):

for col_loc, col in zip(b.ref_locs, d):
# self.data is a preallocated list
self.data[self.column_map[b][i]] = d[i]
self.data[col_loc] = col

ix = data_index.to_native_types(slicer=slicer, na_rep=self.na_rep,
float_format=self.float_format,
Expand Down
33 changes: 15 additions & 18 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1952,7 +1952,9 @@ def _ensure_valid_index(self, value):
raise ValueError('Cannot set a frame with no defined index '
'and a value that cannot be converted to a '
'Series')
self._data.set_axis(1, value.index.copy(), check_axis=False)

self._data = self._data.reindex_axis(value.index.copy(), axis=1,
fill_value=np.nan)

# we are a scalar
# noop
Expand Down Expand Up @@ -2646,17 +2648,15 @@ def trans(v):
else:
indexer = _nargsort(labels, kind=kind, ascending=ascending,
na_position=na_position)


bm_axis = self._get_block_manager_axis(axis)
new_data = self._data.take(indexer, axis=bm_axis,
convert=False, verify=False)

if inplace:
if axis == 1:
new_data = self._data.reindex_items(
self._data.items[indexer],
copy=False)
elif axis == 0:
new_data = self._data.take(indexer)
self._update_inplace(new_data)
return self._update_inplace(new_data)
else:
return self.take(indexer, axis=axis, convert=False, is_copy=False)
return self._constructor(new_data).__finalize__(self)

def sortlevel(self, level=0, axis=0, ascending=True, inplace=False):
"""
Expand Down Expand Up @@ -2691,16 +2691,13 @@ def sortlevel(self, level=0, axis=0, ascending=True, inplace=False):
else:
return self.take(indexer, axis=axis, convert=False)

bm_axis = self._get_block_manager_axis(axis)
new_data = self._data.take(indexer, axis=bm_axis,
convert=False, verify=False)
if inplace:
if axis == 1:
new_data = self._data.reindex_items(
self._data.items[indexer],
copy=False)
elif axis == 0:
new_data = self._data.take(indexer)
self._update_inplace(new_data)
return self._update_inplace(new_data)
else:
return self.take(indexer, axis=axis, convert=False, is_copy=False)
return self._constructor(new_data).__finalize__(self)

def swaplevel(self, i, j, axis=0):
"""
Expand Down
49 changes: 11 additions & 38 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ def f(x):
f = _get_rename_function(v)

baxis = self._get_block_manager_axis(axis)
result._data = result._data.rename(f, axis=baxis, copy=copy)
result._data = result._data.rename_axis(f, axis=baxis, copy=copy)
result._clear_item_cache()

if inplace:
Expand Down Expand Up @@ -1217,21 +1217,9 @@ def take(self, indices, axis=0, convert=True, is_copy=True):
taken : type of caller
"""

# check/convert indicies here
if convert:
axis = self._get_axis_number(axis)
indices = _maybe_convert_indices(
indices, len(self._get_axis(axis)))

baxis = self._get_block_manager_axis(axis)
if baxis == 0:
labels = self._get_axis(axis)
new_items = labels.take(indices)
new_data = self._data.reindex_axis(new_items, indexer=indices,
axis=baxis)
else:
new_data = self._data.take(indices, axis=baxis)

new_data = self._data.take(indices,
axis=self._get_block_manager_axis(axis),
convert=True, verify=True)
result = self._constructor(new_data).__finalize__(self)

# maybe set copy if we didn't actually change the index
Expand Down Expand Up @@ -1719,30 +1707,15 @@ def _reindex_with_indexers(self, reindexers, method=None,

if index is None:
continue
index = _ensure_index(index)

# reindex the axis
if method is not None:
new_data = new_data.reindex_axis(
index, indexer=indexer, method=method, axis=baxis,
fill_value=fill_value, limit=limit, copy=copy)

elif indexer is not None:
# TODO: speed up on homogeneous DataFrame objects
index = _ensure_index(index)
if indexer is not None:
indexer = com._ensure_int64(indexer)
new_data = new_data.reindex_indexer(index, indexer, axis=baxis,
fill_value=fill_value,
allow_dups=allow_dups)

elif (baxis == 0 and index is not None and
index is not new_data.axes[baxis]):
new_data = new_data.reindex_items(index, copy=copy,
fill_value=fill_value)

elif (baxis > 0 and index is not None and
index is not new_data.axes[baxis]):
new_data = new_data.copy(deep=copy)
new_data.set_axis(baxis, index)

# TODO: speed up on homogeneous DataFrame objects
new_data = new_data.reindex_indexer(index, indexer, axis=baxis,
fill_value=fill_value,
allow_dups=allow_dups)

if copy and new_data is self._data:
new_data = new_data.copy()
Expand Down
Loading