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

SNOW-1518378 - Provide a numpy compatibility mapping to np.full_like #2499

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

sfc-gh-jkew
Copy link
Contributor

SNOW-1518378 - Provide a numpy compatibility mapping to np.full_like

This provides a numpy compat mapping to np.full_like; which fills a dataframe/series with a fill value the same shape as the input.

checklist:

  • I am adding a new automated test(s) to verify correctness of my new code
    • If this test skips Local Testing mode, I'm requesting review from @snowflakedb/local-testing
  • I am adding new logging messages
  • I am adding a new telemetry message
  • I am adding new credentials
  • I am adding a new dependency
  • If this is a new feature/behavior, I'm adding the Local Testing parity changes.
  • I acknowledge that I have ensured my changes to be thread-safe. Follow the link for more information: Thread-safe Developer Guidelines

@sfc-gh-jkew sfc-gh-jkew marked this pull request as ready for review October 23, 2024 23:58
@sfc-gh-jkew sfc-gh-jkew requested a review from a team as a code owner October 23, 2024 23:58
Copy link
Contributor

@sfc-gh-mvashishtha sfc-gh-mvashishtha left a comment

Choose a reason for hiding this comment

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

I still have a couple of small unresolved comments

Copy link
Contributor

@sfc-gh-rdurrani sfc-gh-rdurrani left a comment

Choose a reason for hiding this comment

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

Left some nits, but great work overall!

@@ -80,6 +80,9 @@
- Added support for applying Snowpark Python function `snowflake_cortex_summarize`.
- Added support for `DataFrame.attrs` and `Series.attrs`.
- Added support for `DataFrame.style`.
- Added support for `Index.to_numpy`.
Copy link
Contributor

Choose a reason for hiding this comment

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

These are probably merge artifacts?

return NotImplemented
if not order == "K":
return NotImplemented
if dtype is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can't we support dtype here? It just overrides the datatype provided by a right?

result_shape = (result_shape,)
if result_shape is None:
result_shape = a.shape
if len(result_shape) == 2:
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe check if result_shape is list-like? otherwise something like result_shape = 'ab' would enter this conditional?

result_shape = a.shape
if len(result_shape) == 2:
height, width = result_shape # type: ignore
return pd.DataFrame(fill_value, index=range(height), columns=range(width))
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we need to set dtype here? Also if a DataFrame contains multiple dtypes, are the returned object's columns supposed to be the same type as each of the columns mapped positionally?

height, width = result_shape # type: ignore
return pd.DataFrame(fill_value, index=range(height), columns=range(width))
if len(result_shape) == 1:
return pd.Series(fill_value, index=range(result_shape[0]))
Copy link
Contributor

Choose a reason for hiding this comment

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

dtype?

with SqlCounter(query_count=2):
snow_result = np.full_like(snow_df, 1234)
pandas_result = np.full_like(pandas_df, 1234)
assert_array_equal(np.array(snow_result), np.array(pandas_result))
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we be checking if the dataframes are equal?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants