jazzband / tablib

Python Module for Tabular Datasets in XLS, CSV, JSON, YAML, &c.
https://tablib.readthedocs.io/
MIT License
4.59k stars 590 forks source link

Row.lpush error #450

Closed cpzt closed 4 years ago

codecov[bot] commented 4 years ago

Codecov Report

Merging #450 into master will increase coverage by 0.01%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #450      +/-   ##
==========================================
+ Coverage    90.4%   90.41%   +0.01%     
==========================================
  Files          28       28              
  Lines        2585     2588       +3     
==========================================
+ Hits         2337     2340       +3     
  Misses        248      248
Impacted Files Coverage Δ
src/tablib/core.py 82.98% <100%> (ø) :arrow_up:
tests/test_tablib.py 98.52% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 8f39ac5...6a548c2. Read the comment docs.

claudep commented 4 years ago

Thanks. It would be great if you could provide a test case, at least to see what's broken currently!

cpzt commented 4 years ago

Thank you for your prompt response. The test code already exists in TablibTestCase.test_row_lpush, len (john) == len (george) is just a coincidence.

claudep commented 4 years ago

Hmmm... when re-reading this lpush/rpush stuff on Row, it looks like it is completely reversed! And the append is in fact prepeding values. Can you confirm this "mess"?

hugovk commented 4 years ago

Oh, look!

Setup

Python 3.8.1 (v3.8.1:1b293b6006, Dec 18 2019, 14:08:53)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from tablib.core import Row, detect_format
>>> john = Row(('John', 'Adams', 90))
>>> george = Row(('George', 'Washington', 67))
>>> tom = Row(('Thomas', 'Jefferson', 50))
>>> john
['John', 'Adams', 90]
>>> type(john)
<class 'tablib.core.Row'>

lpush

>>> john.lpush(tom)
>>> john
['John', 'Adams', 90, ['Thomas', 'Jefferson', 50]]
>>> john.lpush(george)
>>> john
['John', 'Adams', 90, ['George', 'Washington', 67], ['Thomas', 'Jefferson', 50]]
>>> john[-1]
['Thomas', 'Jefferson', 50]

Reset

>>> john = Row(('John', 'Adams', 90))
>>> john
['John', 'Adams', 90]

append

>>> john.append(tom)
>>> john
[['Thomas', 'Jefferson', 50], 'John', 'Adams', 90]
>>> john.append(george)
>>> john
[['George', 'Washington', 67], ['Thomas', 'Jefferson', 50], 'John', 'Adams', 90]
>>>
cpzt commented 4 years ago

lpush a number will cause an error

>>> from tablib.core import Row
>>> john = Row(('John', 'Adams', 90))
>>>  john.lpush(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/chim/.pyenv/versions/3.7.6/lib/python3.7/site-packages/tablib/core.py", line 77, in lpush
    self.insert(len(value), value)
TypeError: object of type 'int' has no len()

lpush, rpush, append are another issue. BTW, Is there any purpose of this opposite operation design of lpush and rpush?

claudep commented 4 years ago

I created #454, @qianmosolo I would appreciate your review.