-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
REF: collect attribute-setting at the end of create_axes #30029
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
jreback
merged 4 commits into
pandas-dev:master
from
jbrockmendel:cln-pytables-create_axes
Dec 4, 2019
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4f33d77
REF: collect attribute-setting at the end of create_axes
jbrockmendel 81118c0
Merge branch 'master' of https://github.com/pandas-dev/pandas into cl…
jbrockmendel a5417b1
Merge branch 'master' of https://github.com/pandas-dev/pandas into cl…
jbrockmendel c023acf
more descriptive names
jbrockmendel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3681,7 +3681,7 @@ def read_axes( | |
|
||
return True | ||
|
||
def get_object(self, obj): | ||
def get_object(self, obj, transposed: bool): | ||
""" return the data for this obj """ | ||
return obj | ||
|
||
|
@@ -3785,15 +3785,13 @@ def create_axes( | |
) | ||
|
||
# create according to the new data | ||
self.non_index_axes = [] | ||
self.data_columns = [] | ||
nia: List = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any chance of adding a subtype here? |
||
dcs = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
|
||
# nan_representation | ||
if nan_rep is None: | ||
nan_rep = "nan" | ||
|
||
self.nan_rep = nan_rep | ||
|
||
# create axes to index and non_index | ||
index_axes_map = dict() | ||
for i, a in enumerate(obj.axes): | ||
|
@@ -3810,7 +3808,7 @@ def create_axes( | |
# necessary | ||
append_axis = list(a) | ||
if existing_table is not None: | ||
indexer = len(self.non_index_axes) | ||
indexer = len(nia) | ||
exist_axis = existing_table.non_index_axes[indexer][1] | ||
if not array_equivalent( | ||
np.array(append_axis), np.array(exist_axis) | ||
|
@@ -3827,34 +3825,37 @@ def create_axes( | |
info["names"] = list(a.names) | ||
info["type"] = type(a).__name__ | ||
|
||
self.non_index_axes.append((i, append_axis)) | ||
nia.append((i, append_axis)) | ||
|
||
self.non_index_axes = nia | ||
|
||
# set axis positions (based on the axes) | ||
new_index_axes = [index_axes_map[a] for a in axes] | ||
for j, iax in enumerate(new_index_axes): | ||
iax.set_pos(j) | ||
iax.update_info(self.info) | ||
self.index_axes = new_index_axes | ||
|
||
j = len(self.index_axes) | ||
j = len(new_index_axes) | ||
|
||
# check for column conflicts | ||
for a in self.axes: | ||
for a in new_index_axes: | ||
a.maybe_set_size(min_itemsize=min_itemsize) | ||
|
||
# reindex by our non_index_axes & compute data_columns | ||
for a in self.non_index_axes: | ||
for a in nia: | ||
obj = _reindex_axis(obj, a[0], a[1]) | ||
|
||
def get_blk_items(mgr, blocks): | ||
return [mgr.items.take(blk.mgr_locs) for blk in blocks] | ||
|
||
transposed = new_index_axes[0].axis == 1 | ||
|
||
# figure out data_columns and get out blocks | ||
block_obj = self.get_object(obj)._consolidate() | ||
block_obj = self.get_object(obj, transposed)._consolidate() | ||
blocks = block_obj._data.blocks | ||
blk_items = get_blk_items(block_obj._data, blocks) | ||
if len(self.non_index_axes): | ||
axis, axis_labels = self.non_index_axes[0] | ||
if len(nia): | ||
axis, axis_labels = nia[0] | ||
data_columns = self.validate_data_columns(data_columns, min_itemsize) | ||
if len(data_columns): | ||
mgr = block_obj.reindex( | ||
|
@@ -3892,7 +3893,7 @@ def get_blk_items(mgr, blocks): | |
blk_items = new_blk_items | ||
|
||
# add my values | ||
self.values_axes = [] | ||
vaxes = [] | ||
for i, (b, b_items) in enumerate(zip(blocks, blk_items)): | ||
|
||
# shape of the data column are the indexable axes | ||
|
@@ -3906,7 +3907,7 @@ def get_blk_items(mgr, blocks): | |
if not (name is None or isinstance(name, str)): | ||
# TODO: should the message here be more specifically non-str? | ||
raise ValueError("cannot have non-object label DataIndexableCol") | ||
self.data_columns.append(name) | ||
dcs.append(name) | ||
|
||
# make sure that we match up the existing columns | ||
# if we have an existing table | ||
|
@@ -3934,10 +3935,15 @@ def get_blk_items(mgr, blocks): | |
) | ||
col.set_pos(j) | ||
|
||
self.values_axes.append(col) | ||
vaxes.append(col) | ||
|
||
j += 1 | ||
|
||
self.nan_rep = nan_rep | ||
self.data_columns = dcs | ||
self.values_axes = vaxes | ||
self.index_axes = new_index_axes | ||
|
||
# validate our min_itemsize | ||
self.validate_min_itemsize(min_itemsize) | ||
|
||
|
@@ -4390,9 +4396,9 @@ class AppendableFrameTable(AppendableTable): | |
def is_transposed(self) -> bool: | ||
return self.index_axes[0].axis == 1 | ||
|
||
def get_object(self, obj): | ||
def get_object(self, obj, transposed: bool): | ||
""" these are written transposed """ | ||
if self.is_transposed: | ||
if transposed: | ||
obj = obj.T | ||
return obj | ||
|
||
|
@@ -4474,7 +4480,7 @@ class AppendableSeriesTable(AppendableFrameTable): | |
def is_transposed(self) -> bool: | ||
return False | ||
|
||
def get_object(self, obj): | ||
def get_object(self, obj, transposed: bool): | ||
return obj | ||
|
||
def write(self, obj, data_columns=None, **kwargs): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any chance of adding a subtype here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the rename? I would imagine
non_index_axes
newcomer friendly than a TLA.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i wanted something not-identical to the self.foo name for grepping purposes, but can try to find a middle ground that is more descriptive
I'll give it the ol' college try.