Skip to content
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

change inspect to print, add get_inspect to get object, make more uni… #435

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions integration-tests/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ rm -f tests/test_docs_generated.py

echo "$NAME rm -r tests/sandbox/*"
rm -rf tests/sandbox/*

echo "$NAME rm -r tests/.coverage*"
rm -f tests/.coverage*
13 changes: 11 additions & 2 deletions integration-tests/runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,22 @@ if [ -z "$HADOOP_CONF_DIR" ]; then
fi
echo $NAME HADOOP_CONF_DIR=$HADOOP_CONF_DIR

doctgen_args=""
other_args=""
if [ $1 = "--skiplong" ]; then
doctgen_args="--skiplong"
shift
other_args="--ignore=test_dicom.py --ignore=test_graph.py"
fi

echo "$NAME Calling clean.sh"
./clean.sh

cd tests


echo "$NAME Generating the doctests test file"
python2.7 doctgen.py
python2.7 doctgen.py $doctgen_args
GEN_DOCTESTS_SUCCESS=$?
if [[ $GEN_DOCTESTS_SUCCESS != 0 ]]
then
Expand All @@ -55,4 +64,4 @@ fi
#python2.7 -m pytest -k test_kmeans # example to run individual test
#python2.7 -m pytest -k test_docs_python_sparktk_frame_ops_drop_columns_py # example to run individual doc test
export COVERAGE_FILE=$DIR/../coverage/integration_test_coverage.dat
py.test --cov-config=$DIR/pycoverage.ini --cov=$DIR/../python --cov-report=html:$DIR/../coverage/pytest_integration $@
py.test --cov-config=$DIR/pycoverage.ini --cov=$DIR/../python --cov-report=html:$DIR/../coverage/pytest_integration $other_args $@
11 changes: 10 additions & 1 deletion integration-tests/tests/doctgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def _trim_test_path(path):
def filter_exemptions(paths):
"""returns the given paths with the exemptions removed"""
chop = len(path_to_frameops) + 1 # the + 1 is for the extra forward slash
filtered_paths = [p for p in paths if p[chop:] not in exemptions]
filtered_paths = [p for p in paths if p and p[chop:] not in exemptions]
return filtered_paths


Expand Down Expand Up @@ -229,6 +229,15 @@ def main():
else:
print "[%s] Removed pre-existing .pyc file %s" % (this_script_name, pyc)

if '--skiplong' in sys.argv:
print "[%s] --skiplong argument found, skipping dicom, graph tests, maybe more" % this_script_name
global path_to_dicom, path_to_dicomops, path_to_graph, path_to_graphops
path_to_dicom = ''
path_to_dicomops = ''
path_to_graph = ''
path_to_graphops = ''


# Python flatmap --> [item for list in listoflists for item in list]
test_paths = [test_path for folder_path in [path_to_frameops,
path_to_framecons,
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/tests/test__smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_back_and_forth_py_scala(tc):
f.bin_column("a", [5, 8, 10.0, 30.0, 50, 80])
# python
f.filter(lambda row: row.a > 5)
results = str(f.inspect())
results = str(f.get_inspect())
expected = """[#] a b c a_binned
============================
[0] 6 six 10 0
Expand Down
13 changes: 11 additions & 2 deletions python/sparktk/atable.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ def __init__(self, rows, schema, offset, format_settings=None):
def __repr__(self):
return self._repr()

def __unicode__(self):
return unicode(self._repr())

def _repr_wrap(self):
"""print rows in a 'clumps' style"""
row_index_str_format = '[%s]' + ' ' * spaces_between_cols
Expand Down Expand Up @@ -315,7 +318,9 @@ def _get_value_formatter(self, data_type):

@staticmethod
def _get_wrap_entry(data, size, formatter, relative_column_index, extra_tuples):
entry = unicode(formatter(data)).encode('utf-8')
if isinstance(data, str):
data = data.decode('utf-8')
entry = unicode(formatter(data))
if isinstance(data, basestring):
lines = entry.splitlines()
if len(lines) > 1:
Expand Down Expand Up @@ -427,7 +432,11 @@ def _get_col_sizes(rows, row_index, row_count, header_sizes, formatters):
row = rows[r]
for c in xrange(len(sizes)):
value = row[c]
entry = unicode(formatters[c](value))
entry = formatters[c](value)
if isinstance(entry, str):
entry = entry.decode('utf-8')
else:
entry = unicode(entry)
lines = entry.splitlines()
max = 0
for line in lines:
Expand Down
2 changes: 1 addition & 1 deletion python/sparktk/frame/constructors/import_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def import_csv(path, delimiter=",", header=False, schema=None, datetime_format="
>>> frame = tc.frame.import_csv(file_path, schema=schema, header=False)
-etc-

>>> frame.inspect()
>>> print unicode(frame.get_inspect()).encode('utf-8') # because this file if UT8 and this docstring is str
[#] a b c
============
[0] à ë ñ
Expand Down
2 changes: 1 addition & 1 deletion python/sparktk/frame/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def column_names(self):
from sparktk.frame.ops.flatten_columns import flatten_columns
from sparktk.frame.ops.group_by import group_by
from sparktk.frame.ops.histogram import histogram
from sparktk.frame.ops.inspect import inspect
from sparktk.frame.ops.inspect import inspect, get_inspect
from sparktk.frame.ops.join_cross import join_cross
from sparktk.frame.ops.join_inner import join_inner
from sparktk.frame.ops.join_left import join_left
Expand Down
22 changes: 22 additions & 0 deletions python/sparktk/frame/ops/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,28 @@ def inspect(self,
with_types False

"""
atable = self.get_inspect(n=n,
offset=offset,
columns=columns,
wrap=wrap,
truncate=truncate,
round=round,
width=width,
margin=margin,
with_types=with_types)
print unicode(atable)


def get_inspect(self,
n=10,
offset=0,
columns=None,
wrap=inspect_settings._unspecified,
truncate=inspect_settings._unspecified,
round=inspect_settings._unspecified,
width=inspect_settings._unspecified,
margin=inspect_settings._unspecified,
with_types=inspect_settings._unspecified):
from sparktk.frame.ops.take import take_rich
format_settings = inspect_settings.copy(wrap, truncate, round, width, margin, with_types)
result = take_rich(self, n, offset, columns)
Expand Down
4 changes: 2 additions & 2 deletions python/sparktk/graph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ class Graph(object):

>>> assert str(graph) == str(example)

>>> assert str(example.create_vertices_frame().inspect(20)) == str(vertices.inspect(20))
>>> assert str(example.create_vertices_frame().get_inspect(20)) == str(vertices.get_inspect(20))

>>> assert str(example.create_edges_frame().inspect(20)) == str(edges.inspect(20))
>>> assert str(example.create_edges_frame().get_inspect(20)) == str(edges.get_inspect(20))

</hide>

Expand Down