code: def test_apply_categorical_with_nan_values(series, by_row):
      # GH 20714 bug fixed in: GH 24275
      s = Series(series, dtype="category")
      if not by_row:
          msg = "'Series' object has no attribute 'split'"
          with pytest.raises(AttributeError, match=msg):
              s.apply(lambda x: x.split("-")[0], by_row=by_row)
          return
  
      result = s.apply(lambda x: x.split("-")[0], by_row=by_row)
      result = result.astype(object)
      expected = Series(["1", "1", np.nan], dtype="category")
      expected = expected.astype(object)
      tm.assert_series_equal(result, expected)
  
imports: import numpy
  import pytest
  import pandas
  from pandas import DataFrame, Index, MultiIndex, Series, concat, date_range, timedelta_range
  import pandas._testing
  from pandas.tests.apply.common import series_transform_kernels
label_desc: Use image node_id 16 for calling a global function with example usage: test_apply_categorical_with_nan_values(series, by_row) without return types