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

Implements pct_change() for DataFrame #1051

Merged
merged 5 commits into from
Dec 12, 2019

Conversation

itholic
Copy link
Contributor

@itholic itholic commented Nov 18, 2019

Resolves #878
(https://pandas.pydata.org/pandas-docs/version/0.23.4/generated/pandas.DataFrame.pct_change.html)

>>> df = ks.DataFrame({
...     'FR': [4.0405, 4.0963, 4.3149],
...     'GR': [1.7246, 1.7482, 1.8519],
...     'IT': [804.74, 810.01, 860.13]},
...     index=['1980-01-01', '1980-02-01', '1980-03-01'])
>>> df
                FR      GR      IT
1980-01-01  4.0405  1.7246  804.74
1980-02-01  4.0963  1.7482  810.01
1980-03-01  4.3149  1.8519  860.13

>>> df.pct_change()
                  FR        GR        IT
1980-01-01       NaN       NaN       NaN
1980-02-01  0.013810  0.013684  0.006549
1980-03-01  0.053365  0.059318  0.061876

You can set periods to shift for forming percent change

>>> df.pct_change(2)
                  FR        GR       IT
1980-01-01       NaN       NaN      NaN
1980-02-01       NaN       NaN      NaN
1980-03-01  0.067912  0.073814  0.06883

@codecov-io
Copy link

codecov-io commented Nov 18, 2019

Codecov Report

Merging #1051 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1051      +/-   ##
==========================================
+ Coverage   95.14%   95.14%   +<.01%     
==========================================
  Files          35       35              
  Lines        7003     7010       +7     
==========================================
+ Hits         6663     6670       +7     
  Misses        340      340
Impacted Files Coverage Δ
databricks/koalas/missing/frame.py 100% <ø> (ø) ⬆️
databricks/koalas/frame.py 96.81% <100%> (+0.01%) ⬆️

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 63d42c3...d8c75f2. Read the comment docs.

Copy link
Member

@HyukjinKwon HyukjinKwon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM otherwise

@HyukjinKwon
Copy link
Member

@itholic can you resolve conflicts?

@itholic
Copy link
Contributor Author

itholic commented Dec 10, 2019

@HyukjinKwon resolved, Thanks 😄

@softagram-bot
Copy link

Softagram Impact Report for pull/1051 (head commit: d8c75f2)

⚠️ Copy paste found

ℹ️ test_dataframe.py: Copy paste fragment on line 31 shared with ../test_numpy_compat.py:


    @property
    def pdf(self):
        return pd.DataFrame({
            'a': [1, 2, 3, 4, 5, 6, 7, 8, 9],
            'b': [4, 5, 6, 3, 2, 1, ...(truncated 160 chars)

ℹ️ test_dataframe.py: Copy paste fragment on line 31 shared with ../test_indexes.py, ../test_numpy_compat.py:


    @property
    def pdf(self):
        return pd.DataFrame({
            'a': [1, 2, 3, 4, 5, 6, 7, 8, 9],
            'b': [4, 5, 6, 3, 2, 1, ...(truncated 160 chars)

ℹ️ test_dataframe.py: Copy paste fragment on line 34 shared with ../test_indexes.py, ../test_numpy_compat.py, ../test_ops_on_diff_frames.py:

        return pd.DataFrame({
            'a': [1, 2, 3, 4, 5, 6, 7, 8, 9],
            'b': [4, 5, 6, 3, 2, 1, 0, 0, 0],
        }, index=[0, 1, 3, 5, 6, 8, 9, 9, 9])

    @propert...(truncated 20 chars)

ℹ️ test_dataframe.py: Copy paste fragment inside the same file on lines 1281, 1301:

                       pdf.replace([0, 1, 2, 3, 5, 6], 4))

        self.assert_eq(kdf.replace([0, 1, 2, 3, 5, 6], [6, 5, 4, 3, 2, 1]),
     ...(truncated 253 chars)

ℹ️ test_dataframe.py: Copy paste fragment inside the same file on lines 2105, 2154:


        self.assert_eq(kdf.filter(like='b', axis='index'), pdf.filter(like='b', axis='index'))
        self.assert_eq(kdf.filter(like=...(truncated 312 chars)

ℹ️ test_dataframe.py: Copy paste fragment inside the same file on lines 1508, 1578:

                                  \"bar\", \"bar\", \"bar\", \"bar\"],
                            \"B\": [\"one\", \"one\", \"one\", \"two\", \"two\",...(truncated 434 chars)

ℹ️ test_dataframe.py: Copy paste fragment inside the same file on lines 579, 626:

        self.assert_eq(pdf.fillna(method='ffill'), kdf.fillna(method='ffill'))
        self.assert_eq(pdf.fillna(method='ffill', limit=2...(truncated 215 chars)

ℹ️ test_dataframe.py: Copy paste fragment inside the same file on lines 497, 2072, 2081:

        pdf = pd.DataFrame({'x': [np.nan, 2, 3, 4, np.nan, 6],
                            'y': [1, 2, np.nan, 4, np.nan, np.nan],
                            'z': [1, 2, 3,...(truncated 166 chars)

ℹ️ test_dataframe.py: Copy paste fragment inside the same file on lines 497, 569, 2072, 2081:

        pdf = pd.DataFrame({'x': [np.nan, 2, 3, 4, np.nan, 6],
                            'y': [1, 2, np.nan, 4, np.nan, np.nan],
                            'z': [1, 2, 3,...(truncated 166 chars)

ℹ️ test_dataframe.py: Copy paste fragment inside the same file on lines 1376, 1538:

        pdf = pd.DataFrame({'a': [4, 2, 3, 4, 8, 6],
                            'b': [1, 2, 2, 4, 2, 4],
                            'e': [1, 2, 2, 4, 2, 4],
  ...(truncated 145 chars)

ℹ️ test_dataframe.py: Copy paste fragment inside the same file on lines 1652, 1670, 1688:

        arrays = [np.array(['A', 'A', 'B', 'B']),
                  np.array(['one', 'two', 'one', 'two'])]
        pdf = pd.DataFrame(np.random.randn(3, ...(truncated 153 chars)

ℹ️ test_dataframe.py: Copy paste fragment inside the same file on lines 1352, 1368:


        left_kdf, left_pdf, right_kdf, right_pdf = get_data(left_columns=left_columns,
                                    ...(truncated 270 chars)

ℹ️ test_dataframe.py: Copy paste fragment inside the same file on lines 1876, 1904:

        pdf = pd.DataFrame({
            'col1': [False, False, False],
            'col2': [True, False, False],
            'col3': [0, 0, 1],
            'col4': [0, 1, 2],
...(truncated 163 chars)

ℹ️ test_dataframe.py: Copy paste fragment inside the same file on lines 819, 835:

        pdf = pd.DataFrame({'a': [4, 2, 3, 4, 8, 6],
                            'b': [1, 2, 9, 4, 2, 4],
                            'c': [\"one\", \"three\", \"six\", \"seven\",...(truncated 108 chars)

ℹ️ test_dataframe.py: Copy paste fragment inside the same file on lines 79, 146:

        pdf = pd.DataFrame({
            ('x', 'a', '1'): [1, 2, 3],
            ('x', 'b', '2'): [4, 5, 6],
            ('y.z', 'c.d', '3'): [7, 8, 9]...(truncated 72 chars)

ℹ️ frame.py: Copy paste fragment on line 5771 shared with ../namespace.py:

              on: Union[str, List[str], Tuple[str, ...], List[Tuple[str, ...]]] = None,
              left_on: Union[str, List[str], Tuple[s...(truncated 273 chars)

ℹ️ frame.py: Copy paste fragment on line 1530 shared with ../series.py:


    def to_latex(self, buf=None, columns=None, col_space=None, header=True, index=True,
                 na_rep='NaN',...(truncated 256 chars)

ℹ️ frame.py: Copy paste fragment inside the same file on lines 7269, 7352:


        # TODO: there is a similar logic to transpose in, for instance,
        #  DataFrame.any, Series.quantile. Maybe ...(truncated 1065 chars)

ℹ️ frame.py: Copy paste fragment inside the same file on lines 4900, 4921:

            sdf = self._sdf.select(
                self._internal.index_scols +
                [self._internal.scol_for(idx...(truncated 466 chars)

ℹ️ frame.py: Copy paste fragment inside the same file on lines 503, 910, 1910, 2855, 2939, 6733:


            sdf = self._sdf.select(
                self._internal.index_scols + [c._scol for c in applied])
            internal = self....(truncated 430 chars)

Now that you are on the file, it would be easier to pay back some tech. debt.

⭐ Change Overview

Showing the changed files, dependency changes and the impact - click for full size
(Open in Softagram Desktop for full details)

📄 Full report

Impact Report explained. Give feedback on this report to [email protected]

@HyukjinKwon HyukjinKwon merged commit 0cbedc1 into databricks:master Dec 12, 2019
@itholic itholic deleted the f_pct_change branch December 20, 2019 04:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DataFrame.pct_change
4 participants